2



I'm learning Queueable apex and want to make sure I understand what the benefit of chaining jobs is, as opposed to simply calling other class methods within the method synchronously.

Here's my thinking: once an enqueued method has started, it's in an asynchronous context with increased governor limits. Does a chained job start in a new context with reset limits? It sounds like it does, given what the dev guide says about queued jobs only starting when the system has enough resources available, implying that they are completely separate transactions. But I just want to be sure :)

Thanks in advance!

  • 1
    yes - by definition, each queuable job is async and hence gets new limits – cropredy Jan 31 '17 at 17:19
4

Yes, chained job will start in a new context with reset limits. I couldn't find documentation stating this, but a quick POC will confirm (see code below).

From anonymous apex:

System.enqueueJob(new TestQueueable(0));

Calling this class:

public class TestQueueable implements Queueable{

    public Integer num;

    public TestQueueable(Integer num){
        this.num = num;
    }

    public void execute(QueueableContext context){
        Integer c = [SELECT Count() FROM Contact];
        if (num < 3){
            System.enqueueJob(new TestQueueable(num + 1));
        }
        System.debug(Limits.getQueries());
    }

}

You will see in the developer console that each successive queueable creates a new log, and the debug statement will always return 1.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.