Created
September 2, 2012 23:55
-
-
Save sbob-sfdc/3605718 to your computer and use it in GitHub Desktop.
Workshop 203, Tutorial 3, Step 5, Apex
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 HandleOrderUpdate on Invoice__c (after update) { | |
// Create a map of IDs to all of the *old* versions of sObjects | |
// 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>(); | |
// Interate through all of the *new* versions of Invoice | |
// sObjects updated by the call that fires the trigger, adding | |
// corresponding Ids to the invoiceIds List, but *only* when an | |
// sObject'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