Invoking Queueable Apex
Queueable Apex jobs are invoked using the System.enqueueJob
method as shown in the following code snippet:
Id apexJobId = System.enqueueJob(new ExampleQueueable());
As is shown, the System.enqueueJob
method returns an Id
for an AsyncApexJob
sObject instance that we can use to monitor the status of the Queueable Apex job in the same way we monitor the job in a Batch Apex context. It should be noted, however, that as Queueable Apex does not process batches of records, JobItemsProcessed
and TotalJobItems
will always return 0
.
From a synchronous Apex process, we can enqueue 50 jobs but can only enqueue a single job when enqueuing from a Batch Apex or Queueable Apex class (more on this in the next section). There are some shared ways of circumventing this that can be found on the internet, such as scheduling another Apex job that will enqueue the job should you be at the limit of the available jobs in the queue. I would not recommend this for a number of...