Created
April 4, 2015 17:39
-
-
Save tyoshikawa1106/b21d7ba7c7eff5e2272e to your computer and use it in GitHub Desktop.
Integration Workbook Tutorial Apex Trigger
This file contains 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 HandleOrderUpdate on Invoice__c (after update) { | |
// Create a map of IDs to all of the *old* versions of records | |
// updated by the call that fires the trigger. | |
Map<ID, Invoice__c> oldMap = new Map<ID,Invoice__c>(Trigger.old); | |
// Create an empty list of IDs | |
List<Id> invoiceIds = new List<Id>(); | |
// Iterate through all of the *new* versions of Invoice__c | |
// records updated by the call that fires the trigger, adding | |
// corresponding IDs to the invoiceIds list, but *only* when an | |
// invoice's status changed from a non-"Closed" value to "Closed". | |
for (Invoice__c invoice: Trigger.new) { | |
if (invoice.status__c == 'Closed' && oldMap.get(invoice.Id).status__c !='Closed'){ | |
invoiceIds.add(invoice.Id); | |
} | |
} | |
// If the list of IDs is not empty, call Integration.postOrder | |
// supplying the list of IDs for fulfillment. | |
if (invoiceIds.size() > 0) { | |
Integration.postOrder(invoiceIds); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment