Skip to content

Instantly share code, notes, and snippets.

@ckoppelman
Created March 13, 2017 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckoppelman/96d51595124b58d3cd1d3202f18bea9e to your computer and use it in GitHub Desktop.
Save ckoppelman/96d51595124b58d3cd1d3202f18bea9e to your computer and use it in GitHub Desktop.
TriggerUtilities
public class TriggerUtilities {
private TriggerUtilities() {
}
public static Boolean hasAnyFieldChanged(SObject newObj, Map<Id, SObject> oldMap, List<Schema.SObjectField> flds) {
for (Schema.SObjectField fld : flds) {
if (hasFieldChanged(newObj, oldMap, fld)) {
return true;
}
}
return false;
}
public static Boolean hasFieldChanged(SObject newObj, Map<Id, SObject> oldMap, Schema.SObjectField fld) {
if (newObj.Id == null) {
return true;
}
if (oldMap != null && oldMap.containsKey(newObj.Id)) {
SObject oldObj = oldMap.get(newObj.Id);
if (oldObj == null) {
return true;
}
return oldObj.get(fld) != newObj.get(fld);
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment