Skip to content

Instantly share code, notes, and snippets.

@tyoshikawa1106
Created April 4, 2015 17:39
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 tyoshikawa1106/b21d7ba7c7eff5e2272e to your computer and use it in GitHub Desktop.
Save tyoshikawa1106/b21d7ba7c7eff5e2272e to your computer and use it in GitHub Desktop.
Integration Workbook Tutorial Apex Trigger
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