Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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