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