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
  • 1
    yes - by definition, each queuable job is async and hence gets new limits
    – cropredy
    Commented Jan 31, 2017 at 17:19

1 Answer 1

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .