fflib-apex-common icon indicating copy to clipboard operation
fflib-apex-common copied to clipboard

Allow setFieldValueByMap to consume a Map<Id, Id>

Open JAertgeerts opened this issue 3 years ago • 3 comments

This change is Reviewable

JAertgeerts avatar Dec 14 '21 20:12 JAertgeerts

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

  • Why is this change needed?
  • Can you provide corresponding code coverage please?

ImJohnMDaniel avatar Dec 14 '21 20:12 ImJohnMDaniel

@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.

wimvelzeboer avatar Dec 15 '21 09:12 wimvelzeboer

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

ImJohnMDaniel avatar Dec 29 '21 21:12 ImJohnMDaniel