Skip to content

Instantly share code, notes, and snippets.

@Walletau
Created May 24, 2017 16:11
Show Gist options
  • Save Walletau/2280858ff60ae82203e9ace00d690a26 to your computer and use it in GitHub Desktop.
Save Walletau/2280858ff60ae82203e9ace00d690a26 to your computer and use it in GitHub Desktop.
Trigger Context
/**
* This class holds useful information about a trigger event that is taking
* place so that handler classes can make use of this data and don't have to
* pass any individual values.
*/
public class TriggerContext {
public final String objectName;
public final Boolean isBefore;
public final Boolean isAfter;
public final Boolean isInsert;
public final Boolean isUpdate;
public final Boolean isDelete;
public final List<sObject> oldList;
public final List<sObject> newList;
public final Map<Id,sObject> oldMap;
public final Map<id,sObject> newMap;
public final Integer size;
public TriggerContext(String objectName) {
this(objectName, Trigger.isBefore, Trigger.isAfter, Trigger.isInsert, Trigger.isUpdate, Trigger.isDelete, Trigger.old, Trigger.new, Trigger.oldMap, Trigger.newMap, Trigger.size);
}
public TriggerContext(String objectName, Boolean isBefore, Boolean isAfter,
Boolean isInsert, Boolean isUpdate, Boolean isDelete,
List<sObject> oldList, List<sObject> newList, Map<Id,sObject> oldMap, Map<Id,sObject> newMap, Integer size)
{
this.objectName = objectName;
this.isBefore = isBefore;
this.isAfter = isAfter;
this.isInsert = isInsert;
this.isUpdate = isUpdate;
this.isDelete = isDelete;
this.oldList = oldList;
this.newList = newList;
this.oldMap = oldMap;
this.newMap = newMap;
this.size = size;
}
public String asString() {
return 'TriggerContext{objectName='+objectName+',size='+size+',isBefore='+isBefore+',isAfter='+isAfter+',isInsert='+isInsert+',isUpdate='+isUpdate+',isDelete='+isDelete+'}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment