Asynchronous Apex
Apex code can be run in an asynchronous manner using batch classes, and subsequently queued or scheduled. Apex code can also be written to run in the background when it’s asynchronous by using the @future
annotation on methods. All Apex web service callouts are @future
methods, with a callout=true
parameter, in that they are forced to run asynchronously, and in the background, user interface operations are not held up by their invocation.
Another way to think about asynchronous Apex is that it essentially executes in its own time. A bonus of using @future
methods is that the governor limits are higher, meaning SOQL query size and heap size limits are more generous as the execution is in its own time, on its own system thread.
When writing Apex methods that are annotated using @future
, they must be static and only return a void return type – that is, return nothing.
Here’s an example of a bare-bones asynchronous Apex class:
public class...