@@ -257,7 +257,6 @@ public virtual class fflib_SObjects
257257 return result ;
258258 }
259259
260-
261260 protected virtual void setFieldValue (Schema.SObjectField sObjectField , Object value )
262261 {
263262 for (SObject record : getRecords ())
@@ -266,6 +265,52 @@ public virtual class fflib_SObjects
266265 }
267266 }
268267
268+ /**
269+ * Sets a value to the given field only when key field Id value is provided in the given map
270+ *
271+ * @param sObjectIdFieldToCheck The SObject Id Field to match the key against in the provided map
272+ * @param sObjectFieldToUpdate The SObjectField to store the mapped value when the key matches the value in the sObjectFieldToUpdate field
273+ * @param values Map of values to store by the sObjectIdFieldToCheck fields value
274+ */
275+ @TestVisible
276+ protected virtual void setFieldValue (
277+ Schema.SObjectField sObjectIdFieldToCheck ,
278+ Schema.SObjectField sObjectFieldToUpdate ,
279+ Map <Id , Object > values )
280+ {
281+ for (SObject record : getRecords ())
282+ {
283+ Id keyValue = (Id ) record .get (sObjectIdFieldToCheck );
284+ if (values ?. containsKey (keyValue ))
285+ {
286+ record .put (sObjectFieldToUpdate , values .get (keyValue ));
287+ }
288+ }
289+ }
290+
291+ /**
292+ * Sets a value to the given field only when key field String value is provided in the given map
293+ *
294+ * @param sObjectStringFieldToCheck The SObject String Field to match the key against in the provided map
295+ * @param sObjectFieldToUpdate The SObjectField to store the mapped value when the key matches the value in the sObjectFieldToUpdate field
296+ * @param values Map of values to store by the sObjectIdFieldToCheck fields value
297+ */
298+ @TestVisible
299+ protected virtual void setFieldValue (
300+ Schema.SObjectField sObjectStringFieldToCheck ,
301+ Schema.SObjectField sObjectFieldToUpdate ,
302+ Map <String , Object > values )
303+ {
304+ for (SObject record : getRecords ())
305+ {
306+ String keyValue = (String ) record .get (sObjectStringFieldToCheck );
307+ if (values ?. containsKey (keyValue ))
308+ {
309+ record .put (sObjectFieldToUpdate , values .get (keyValue ));
310+ }
311+ }
312+ }
313+
269314 /**
270315 * @param sObjectFieldToCheck The SObjectField to match the key against in the provided map
271316 * @param sObjectFieldToUpdate The SObjectField to store the mapped value when the key matches the value in the sObjectFieldToUpdate field
0 commit comments