Created
March 13, 2017 17:25
-
-
Save ckoppelman/96d51595124b58d3cd1d3202f18bea9e to your computer and use it in GitHub Desktop.
TriggerUtilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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