Chain More Jobs with Queueable Apex

Queueable Apex was introduced in Winter ’15 and enables you to easily start and manage asynchronous processes. Previously, you could chain a queueable job to another job only once. You can now chain a job to another job an unlimited number of times. For Developer Edition and Trial organizations, your chain can have up to five queueable jobs.

Chaining jobs is useful when you need to run a job after some other processing is done. To chain a job to another job, submit the second job from the execute() method of your Queueable class. For example, if you have a second class that’s called SecondJob that implements the Queueable interface, you can add this class to the queue in the execute() method as follows:

public class AsyncExecutionExample implements Queueable {
    public void execute(QueueableContext context) {
        // Your processing logic here       

        // Chain this job to next job by submitting the next job
        System.enqueueJob(new SecondJob());
    }
}

Only one job can be started by a queueable job in the chain.