Newer Version Available
Queueable Interface
Namespace
Usage
To execute Apex as an asynchronous job, implement the Queueable interface and add the processing logic in your implementation of the execute method.
Your class and method implementation must be declared as public or global.
To submit your class for asynchronous execution, call the System.enqueueJob by passing it an instance of your class implementation of the Queueable interface as follows:
Queueable Methods
The following are methods for Queueable.
execute(context)
Signature
public void execute(QueueableContext context)
Parameters
- context
- Type: QueueableContext
- Contains the job ID.
Return Value
Type: Void
Queueable Example Implementation
After you submit your queueable class for execution, the job is added to the queue and will be processed when system resources become available. You can monitor the status of your job programmatically by querying AsyncApexJob or through the user interface in Setup by entering Apex Jobs in the Quick Find box, then selecting Apex Jobs.
To query information about your submitted job, perform a SOQL query on AsyncApexJob by filtering on the job ID that the System.enqueueJob method returns. This example uses the jobID variable that was obtained in the previous example.
Similar to future jobs, queueable jobs don’t process batches, and so the number of processed batches and the number of total batches are always zero.