From 990827963b23fc09f4c233a65861a2ac3fd02079 Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Tue, 14 Dec 2021 21:48:28 +0100 Subject: [PATCH] Allow setFieldValueByMap to consume a Map --- .../main/classes/fflib_SObjects.cls | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sfdx-source/apex-common/main/classes/fflib_SObjects.cls b/sfdx-source/apex-common/main/classes/fflib_SObjects.cls index 1e615afd50c..df5cb33dd0c 100644 --- a/sfdx-source/apex-common/main/classes/fflib_SObjects.cls +++ b/sfdx-source/apex-common/main/classes/fflib_SObjects.cls @@ -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 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 **/