Activity › Forums › Salesforce® Discussions › Can I make Callout from Batch Classes? Is there is any number of limit in Salesforce?
Tagged: Apex Callouts, Apex Limit, Batch Class, Future Method, HTTP Callouts, Salesforce Development, Salesforce Records
-
Can I make Callout from Batch Classes? Is there is any number of limit in Salesforce?
Posted by Suraj on April 10, 2017 at 10:21 AMCan I make Callout from Batch Classes? Is there is any number of limit?
Avnish Yadav replied 7 years, 7 months ago 3 Members · 2 Replies -
2 Replies
-
Hi Suraj
Yes, you can make from Batch Classes.
First, you can’t call a future method from a Batch class. My guess is that the threads generated from batches are considered “future” methods, so trying to do it results in the “Future method cannot be called from a future method” error. So, I removed the future designation from the HTTP callout class.
But what got it for me was making sure to pass the optional scope parameter when my schedulable class calls the batch. Otherwise, I hit the wall for callout limits.
So this:
database.executebatch(b);
Becomes:
database.executebatch(b, 1);
And now the scheduled job runs perfectly, just as if I had manually run it myself.
It’s per each call of execute() in the batch, so for each “batch”, you can call up to 10 HTTP callouts.
If the callout can handle multiple records at a time, do so, and batch up to 10 callouts per batch, otherwise, set the batch scope to 1, so each apex batch handles one record at a time.
Hope it may help you:
- [adinserter block='9']
-
Hi Suraj
Yes you can make from Batch Classes.
Thanks.
Log In to reply.