2

This Set the Maximum Depth of Chained Queueable Jobs (Generally Available) is GA and documented to work in:

Where: This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

When I try this in my scratch org ("edition": "Developer",) using API 62 Apex:

AsyncOptions asyncOptions = new AsyncOptions();
asyncOptions.MaximumQueueableStackDepth = 50;
asyncOptions.MinimumQueueableDelayInMinutes = delayMinutes;
System.enqueueJob(q, asyncOptions);

I get this error:

Cannot reset Maximum Queueable Stack Depth in a queueable

Has anyone seen this working? Any idea why it isn't working in my situation?

(There is an example of it not working here Salesforce Queueable AsyncOptions.)

3
  • Does that code run also when chaining the queueable? Only the first enqueue should set the maxDepth, while chaining should be done via System.enqueueJob(q); without the maxDepth
    – RubenDG
    Commented Oct 17 at 16:30
  • Thanks @RubenDG - that could be the problem. I'll try it.
    – Keith C
    Commented Oct 17 at 17:18
  • Hi @RubenDG yes that was my problem. I see that the example code only sets the value on the first enqueue but does not call out the importance of that. Please post as an answer and I'll vote/accept it. Thank-you!
    – Keith C
    Commented Oct 17 at 17:32

1 Answer 1

3

AsyncOptions.MaximumQueueableStackDepth must be set only the first time you enqueue a queueable, while every time that queueable enqueues itself (chaining) MaximumQueueableStackDepth must not be set, that's why it throws

Cannot reset Maximum Queueable Stack Depth in a queueable

Anyway setting the delay in minutes is fine.

I.E.

public class MyQueueable implements Queueable {
    public void execute(QueueableContext context) {
        // something
        if (!Test.isRunningTest() && otherConditions) {
            // Chaining without overriding MaximumQueueableStackDepth
            System.enqueue(this, 0);
        }
    }

    public static void enqueueAfter(Integer minutes) {
         AsyncOptions asyncOptions = new AsyncOptions();
         asyncOptions.MaximumQueueableStackDepth = 50;
         asyncOptions.MinimumQueueableDelayInMinutes = minutes;
         System.enqueueJob(new MyQueueable(), asyncOptions);
    }
}


MyQueueable.enqueueAfter(1);

You must log in to answer this question.

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