Defining Queueable Apex implementations
Queueable Apex, like Batch Apex, is defined through the implementation of an Apex interface, in this case, the Queueable
interface.
To define a Queueable Apex job, we simply implement this interface, which has a single method, execute(QueueableContext context)
. A very basic implementation would then be the following:
public class ExampleQueueable implements Queueable { public void execute(QueueableContext context) { //Do something } }
As we discussed, unlike our Batch Apex implementations, we must define the scope for the Queueable Apex job to process. We can do this in two ways. We can do it through the use of a query within our execute
method:
public class ExampleQueueable implements Queueable { public void execute(QueueableContext context) { List<Account> accs = [SELECT Id, Name FROM Account ...