Salesfroce Developer Future Methods Using Efficiently

salesforce-developer-future-methods

// Salesforce - Developer - Future Methods - Using future method efficiently:

trigger accountAsyncTrigger on Account (after insert, after update) {
    // By passing the @future method a set of Ids, it only needs to be
    // invoked once to handle all of the data. 
    asyncApex.processAccount(Trigger.newMap.keySet());
}

global class asyncApex {

  @future 
  public static void processAccount(Set<Id> accountIds) {
    List<Contact> contacts = [
      select id, salutation, firstname, lastname, email 
      from Contact where accountId IN :accountIds
    ];
    for (Contact c: contacts) {
      // do something
    }
    update contacts;
  }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License