Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sfdx-source/apex-common/main/classes/fflib_SObjects.cls
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ public virtual class fflib_SObjects
}
}

/**
* @param sObjectFieldToCheck The SObjectField to match the key against in the provided map
* @param sObjectFieldToUpdate The SObjectField to store the mapped value when the key matches the value in the sObjectFieldToUpdate field
* @param values Map of values to store by the sObjectFieldToCheck fields value
*/
protected virtual void setFieldValueByMap(
Schema.SObjectField sObjectFieldToCheck,
Schema.SObjectField sObjectFieldToUpdate,
Map<Id, Id> values)
{
for (SObject record : getRecords())
{
Id keyValue = (Id) record.get(sObjectFieldToCheck);
if (values?.get(keyValue) != null)
{
record.put(sObjectFieldToUpdate, values.get(keyValue));
}
}
}

/**
* Ensures logging of errors in the Domain context for later assertions in tests
**/
Expand Down