Can We Chain a Queueable That Makes a Callout?

Can We Chain a Queueable That Makes a Callout?

On July 27, 2025, Posted by , In Apex,Salesforce Technical Questions, With Comments Off on Can We Chain a Queueable That Makes a Callout?
Can We Chain a Queueable That Makes a Callout

Question

In Apex, we can implement Database.AllowsCallouts in a Queueable class to allow HTTP callouts. However, this seems to interfere with chaining queueable jobs. Consider the following code:

public class ChainQueue implements Queueable, Database.AllowsCallouts {
    public void execute(QueueableContext context) {
        if (QueueUtil.hasNext()) {
            MyWSUtil.makeCallout(QueueUtil.next());
        }
        if (QueueUtil.hasNext()) {
            System.enqueueJob(this);
        }
    }
}

Here, MyWSUtil.makeCallout is a static method performing an HTTP callout using data from a custom object that queues pending integrations. QueueUtil contains methods to retrieve pending queue items and check if more records need processing.

This code fails when a callout occurs, and we attempt to enqueue another job. The error message states:

“Maximum callout depth has been reached.”

When Database.AllowsCallouts is included, System.enqueueJob(this) fails. Without Database.AllowsCallouts, making the callout results in:

“Callout not allowed from this future method.”

Is there a way to allow both callouts and queueable chaining? If not, are there plans to support this in the future?

Answer

As Dan Appleman notes in Advanced Apex, one workaround is to use a @Future method as an intermediary. A Queueable job can call a @Future method, and that method can enqueue another Queueable job, effectively enabling unlimited chaining even if callouts are involved.

Boost your Salesforce career with CRS Info Solutions expert-led Salesforce online training, hands-on projects, and free demo sessions for beginners and professionals!!!

Here’s an example implementation:

public without sharing class ThisQueueable implements Queueable, Database.AllowsCallouts {
    
    // Queueable execution logic
    public void execute(QueueableContext context) {
        // Perform callout or other processing
    }

    @Future(callout=true)
    public static void tryToQueue() {
        System.enqueueJob(new ThisQueueable());
    }
}

Explanation:

The code defines a Queueable class, ThisQueueable, that implements Database.AllowsCallouts to perform callouts within the execute method. It includes a @Future method, tryToQueue, which enqueues a new Queueable job, allowing for chaining. The @Future annotation ensures that the callout can be made and the job can be chained without violating Apex limits.

This approach allows the queueable job to complete while offloading the chaining logic to the @Future method, which avoids the limitation on chaining queueable jobs with callouts.

Another potential workaround is to structure the process using a scheduled Apex job that periodically picks up pending records and enqueues new queueable jobs. However, this approach introduces scheduling delays and may not be as immediate as direct chaining.

As of now, Salesforce does not officially support direct chaining of queueable jobs that make callouts. If such functionality becomes available in a future release, checking Salesforce release notes and developer documentation would be the best way to stay updated.

Summing Up

Chaining a Queueable class that makes a callout directly is not supported due to the “maximum callout depth” limitation. However, you can work around this by using a @Future method to enqueue additional Queueable jobs, enabling indefinite chaining with callouts. This method allows you to bypass the chaining limitation, but Salesforce currently doesn’t support direct chaining of queueables with callouts.

Advance Your Career with Salesforce Training in Noida

Step into the world of Salesforce with our expert-led  Salesforce training in Noida, designed to cater to both beginners and experienced professionals. Master the fundamentals of Salesforce CRM, gain hands-on experience with industry-relevant projects, and prepare for certifications like Salesforce Admin and Developer. Our comprehensive curriculum is tailored to make you job-ready, equipping you with the skills and confidence to thrive in today’s competitive job market.

We emphasize practical, real-world learning to ensure you excel in your Salesforce career. With personalized mentorship, Salesforce course materials, and dedicated support for certifications and interview preparation, you’ll be ready to tackle professional challenges with ease.

join us for a free demo session today and take the first step toward transforming your career with Salesforce expertise!!!

Related Posts:

Salesforce CRM Using Apex And Visualforce Training
Interfaces in Salesforce Apex.

Comments are closed.