Spring 23 – API 57

Add Delay to System.enqueueJob

This is a huge and wonderful feature.

In chapter 7, in particular the section “Going Asynchronous with Queueable Apex”, I discuss design patterns around chaining queueables and note that it’s possible to create bugs that lead to infinite chaining that cannot be aborted.

Even with correct code, you may have an application that tries to process very large numbers of queueables – enough that they may consume a significant amount of the available asynchronous requests for an org. When using a centralized async processor (with an async request object as described in the book), a good solution is to merge requests so that you run fewer queueable operations.

This new feature allows you to specify a delay when chaining – offering yet another approach for preventing excessive consumption of async operations. There’s also an option to specify an org wide default delay – though I see this more as a tool for system administrators than something developers will use. Indeed, I can see developers switching to setting an explicit delay on their queueable requests in order to prevent admins from impacting the performance of their code. We’ll see.

I expect there will be more interesting design patterns appearing around this feature. It’s definitely one to pay attention to.