Defining future methods
A future method must be defined as a static
method with a void
return type, as shown in the following code snippet. We annotate the method with the @future
annotation to inform the compiler that this method should be called and placed into the asynchronous processing queue:
@future public static void myFutureMethod() { //method for execution }
The method must be static
so that it can be called and executed without the need for any state to be stored for it to execute.
We can also specify callout = true
in the @future
annotation to declare that the method can make callouts. By default, a standalone @future
annotation is the same as @future(callout = false)
, barring our future method from making callouts to external systems. A method defined to make callouts would then be declared as follows:
@future(callout = true) public static void myFutureCalloutMethod() { //make an API request }
Our future method may have parameters in its definition; however...