Queueable Apex is another asynchronous type of apex. It runs in a separate thread and executes whenever the resources are available. In this type, we can queue our jobs and it is used to run long-running operations. Here we can get the job Id to monitor our jobs.Syntax :
public class UpdateAccountsJob implements Queueable {
public void execute(QueueableContext context) {
List<Account> accounts = [SELECT Id, Name FROM Account WHERE Industry = 'Technology'];
for (Account acc : accounts) {
acc.Industry = 'Updated Industry';
}
update accounts;
}
}
// To run it:
System.enqueueJob(new UpdateAccountsJob());Here are some key features of Queueable Class:
1) A class and method that can be added to the queue to be executed.2) It’s monitorable and abortable.3) It’s chain able.4) A public class that implements the Queueable interface5) Includes an execute method that accepts only a Queueable Context parameter.6) The execute method can access instance properties for the class.7) Returns void.8) Launch by calling System.enqueueJob(cls) with an instance of the class.9) Returns an AsyncApexJob Id