Salesforce Developer Future Methods Syntax

salesforce-developer-future-methods

// Salesforce - Developer - Apex - Future Methods - Syntax:

Future methods must be static methods, and can only return a void type. The 
specified parameters must be primitive data types, arrays of primitive data 
types, or collections of primitive data types. Notably, future methods can’t 
take standard or custom objects as arguments. A common pattern is to pass the 
method a List of record IDs that you want to process asynchronously.

global class SomeClass {
  @future
  public static void someFutureMethod(List<Id> recordIds) {
    List<Account> accounts = [Select Id, Name from Account Where Id IN :recordIds];
    // process account records to do awesome stuff
  }
}

The reason why objects can’t be passed as arguments to future methods is because 
the object can change between the time you call the method and the time that it 
actually executes. Remember, future methods are executed when system resources 
become available. In this case, the future method may have an old object value 
when it actually executes, which can cause all sorts of bad things to happen.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License