[SalesForce] Callout Limits for future methods and queueable apex

I'm aware from the docs that

"A single Apex transaction can make a maximum of 100 callouts to an HTTP request or an API call."

Is anyone aware if that limit is higher in a future methods or queueable apex? Generally, limits are relaxed in an asynchronous context with apex, but I can't find anything talking about callout limits specifically.

I need to make this callout from a trigger, so it looks like future or queueables are my only options.

Best Answer

I quickly wrote a class with future method to test this behaviour.

public class FutureClassLimitsTest {

    @future(callout=true)
    public static void docallouts(){

        for(Integer i=0;i<200;i++){
            Http http=new Http();
            HttpRequest hr=new HttpRequest();
            hr.setMethod('POST');
            hr.setEndpoint('https://google.com');
            http.send(hr);
        }


    }

}

This is the error I get. enter image description here

First error: Too many callouts: 101.

So I believe this is uniform for the whole platform irrespective of the transaction(Sync or Async).

Is there a workaround?

Well unless there is a strong business requirement it is kinda bad doing so many callous in a transaction.

We can call a Queauble Method from Queueable method,.. and you can chain them infinitely. Thus using proper implementation you can have 100+ callouts. Batch is another way to tackle this. You have to write /modify data model add a some queue custom SOBJECT to handle your problem.

No limit is enforced on the depth of chained jobs, which means that you can chain one job to another job and repeat this process with each new child job to link it to a new child job. For Developer Edition and Trial organizations, the maximum stack depth for chained jobs is 5, which means that you can chain jobs four times and the maximum number of jobs in the chain is 5, including the initial parent queueable job.

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm

Related Topic