Created
January 19, 2017 19:57
-
-
Save gitmatheus/ba45efb4c6199ef49c11cef0aef8fa48 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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