apex-enterprise-patterns / fflib-apex-common

Common Apex Library supporting Apex Enterprise Patterns and much more!
BSD 3-Clause "New" or "Revised" License
903 stars 514 forks source link

Allow setFieldValueByMap to consume a Map<Id, Id> #390

Open JAertgeerts opened 2 years ago

JAertgeerts commented 2 years ago

This change is Reviewable

ImJohnMDaniel commented 2 years ago

@JAertgeerts -- thanks for the PR. A couple of questions:

wimvelzeboer commented 2 years ago

@ImJohnMDaniel The purpose of the domain is to allow easy access to the list of objects it contains. There are three primary types of methods on the domain; getters, setters and filter methods. The more standard setter methods we have in the fflib_SObjects domain class, the smaller the methods can become on the domain classes (e.g. Accounts).

This method allows for easy setting and Id field based on the provided map. An example would be the following method, which sets the Case.OwnerId based on the provided map. It check if the Case.AccountId is populated in the map, if so, then it takes the value of that key and sets it to the provided target field, the Case.OwernId.

public ICases setOwnerIdByAccountId(Map<Id, Id> UserIdByAccountId)
{
   setFieldValueByMap(Case.AccountId, Case.OwnerId, UserIdByAccountId);
   return this;
}

Since Salesforce is a bit limited with casting a Map<Object, Object> to a Map<Id, Id> we need another method overload.

ImJohnMDaniel commented 2 years ago

@JAertgeerts, just following up on the request to provide matching code coverage for this method. Cheers!