Skip to content

Instantly share code, notes, and snippets.

@pcon
Created May 30, 2012 18:01
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 pcon/2837986 to your computer and use it in GitHub Desktop.
Save pcon/2837986 to your computer and use it in GitHub Desktop.
Checking previous status != 'In Review' and then switched to 'In Review' - field expression now allowed for generic SObject line 33
public class ServiceRequestTrigger {
private final Map<Id, Service_Request__c> oldMap;
private final Map<Id, Service_Request__c> newMap;
private final List<Service_Request__c> newObjs;
private final Boolean isInsert;
private final Boolean isUpdate;
private final Boolean isDelete;
private final Boolean isBulk;
/**
* The constructor
*
* @param xoldMap The old map from the trigger
* @param xnewObj The list of new objects from the trigger
* @param isBefore If the trigger is in before or after
*/
public ServiceRequestTrigger(Map<Id, Service_Request__c> xoldMap, List<Service_Request__c> xnewObjs, Boolean isBefore) {
oldMap = xoldMap;
newObjs = xnewObjs;
if (!isBefore && newObjs != null) {
newMap = new Map<Id, Service_Request__c>(newObjs);
}
isDelete = (((newObjs == null || newObjs.isEmpty()) && isBefore) || ((newMap == null || newMap.isEmpty()) && !isBefore));
isUpdate = ! (isDelete || oldMap == null || oldMap.isEmpty());
isInsert = ! (isDelete || isUpdate);
isBulk = (newObjs != null && newObjs.size() > 1) ? true : false;
}
public void doAwesomeness() {
for (Service_Request__c srf: newObjs) {
if (
oldMap.get(srf.ID) != null &&
oldMap.get(srf.ID).Status__c != srf.Status__c &&
srf.Status__c == 'In Review'
) {
//do stuff
}
}
}
/**
* Method to initiate trigger logic
*
* @param oldMap The old map from the trigger
* @param newObj The list of new objects from the trigger
* @param isBefore If the trigger is in before or after
*/
public static void processTrigger(Map<Id, Service_Request__c> oldMap, List<Service_Request__c> newObj, Boolean isBefore) {
final ServiceRequestTrigger myTrigger = new ServiceRequestTrigger(oldMap, newObj, isBefore);
if (!isBefore) {
myTrigger.doAwesomeness();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment