function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jack A 2Jack A 2 

How to chain job using Queueable Apex

I am trying to chain job but the inner class code is not executing.
public class MyQueueable1 implements Queueable {

    Public Static list < Account > acclist = new list < Account > ();
    public MyQueueable1() {

    }
    public void execute(QueueableContext context) {

        System.enqueueJob(new MyQueueable2());
    }
    public class MyQueueable2 implements Queueable {

        public MyQueueable2() {

        }
        public void execute(QueueableContext context) {
            List < Account > a = [SELECT Id, Name
                                  FROM Account WHERE Id =: acclist];
        }
    }
}

 
Ramssf70Ramssf70
HI Jack A 2,
refer this link it may helpful for you

http://www.infallibletechie.com/2016/08/queueable-apex.html

Thank you
CloudGeekCloudGeek
Hey Jack,

Chaining Jobs:
If you need to run a job after some other processing is done first by another job, you can chain queueable jobs. To chain a job to another job, submit the second job from the execute() method of your queueable class. You can add only one job from an executing job, which means that only one child job can exist for each parent job. For example, if you have a second class 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());
    }
}

For more deep dive : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm

Note: Please mark this as best answer to help others, if this resolves what you are trying to resolve.