Skip to content

Instantly share code, notes, and snippets.

@gitmatheus
Created January 19, 2017 19:57
Show Gist options
  • Save gitmatheus/ba45efb4c6199ef49c11cef0aef8fa48 to your computer and use it in GitHub Desktop.
Save gitmatheus/ba45efb4c6199ef49c11cef0aef8fa48 to your computer and use it in GitHub Desktop.
trigger MaintenanceRequest on Case (after update) {
// This is an after update trigger, but you can use the same structure for other trigger events.
// Remember: One trigger per object.
//Create a Map to store the Maintenance Requests to evaluate:
Map<Id, Case> casesToEvaluate = new Map<Id, Case>();
if(Trigger.isAfter && Trigger.isUpdate){
for(Case maintenance : Trigger.new){
// Check if this Maintenance Type and Status follow the requirements:
if((maintenance.Type.contains('Repair') || maintenance.Type.contains('Routine Maintenance')) && maintenance.Status == 'Closed'){
casesToEvaluate.put(maintenance.Id,maintenance);
}
}
}
// Simple! With the collection of Cases in a Map, we can invoke the method from the handler class:
MaintenanceRequestHelper.updateWorkOrders(casesToEvaluate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment