Salesforce Developer Future Methods Purpose

salesforce-developer-future-methods

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

Future methods are typically used for:

1. Callouts to external Web services. If you are making callouts from a trigger 
   or after performing a DML operation, you must use a future or queueable 
   method. A callout in a trigger would hold the database connection open for 
   the lifetime of the callout and that is a "no-no" in a multitenant 
   environment.

2. Operations you want to run in their own thread, when time permits such as 
   some sort of resource-intensive calculation or processing of records.

3. Isolating DML operations on different sObject types to prevent the mixed DML 
   error. This is somewhat of an edge-case but you may occasionally run across 
   this issue. See sObjects That Cannot Be Used Together in DML Operations for 
   more details.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License