function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DHO_604DHO_604 

too many callouts: 11 and cannot bulkify callouts

Dear Apex friends,

 

Is there anyway to get around the "too many callouts: 11" problem when I cannot bulkify my callouts?

 

TIA

 

D

MattLacey.ax1065MattLacey.ax1065

Hey D,

 

You could process all of the items you need in a batch apex class, though each invokation of execute can only make one callout, so be sure to set the batch size to 1:

 

Database.executeBatch(new MyBatchClassThatDoesCallouts(), 1);

 

DHO_604DHO_604
Thanks for the headsup MattLacey! I'm struggling a bit on getting this going. I've set up the Batch class, implemented the interfaces, with the execute method calling my desired callout mehtod, but it doesn't want to listen. Would you have some code samples that I can reference? Thanks!
DHO_604DHO_604
The problem now is that I got the 'Too many callouts: 2' problem, although I've set the 2nd parameter of the Database.executeBatch to 1. Any advice would be greatly appreciated!
DHO_604DHO_604

Hi Matt, my code sequence requires 3 callouts for each record, in sequence. Does that mean I have to write an batch class for each callout?

dmchengdmcheng

That is correct - the batch execute method has a limit of one callout, so if each record requires 3 callouts, you'll need three separate batch classes.

Juan NúñezJuan Núñez

This may come in a little late, but...

You can add the implementation "Database.AllowsCallouts" to the class declaration, then you only have to meet the governor limits (more than one, for sure)

Mayank_JoshiMayank_Joshi
I had a similar situation for sending more than 10 records using batch apex . Finally , I resolved this issue and now batch is successfully processing 'n' number of records in Outbound Callouts .

Here Few things need to be focused :

1 : global class Send_closed_CA implements Database.Batchable<Sobject>, Database.AllowsCallouts{ }

Always required - Database.AllowsCallouts while implementing batch for outbound callouts .

2: Next , most Important . As per documentation Batch Apex can process 200 Records per batch . But , while making callouts Batch Apex can only process 1 record per batch(as per documentation) .To overcome this ,we have to make scope of 1 within a batch .

That means , if we are going to send(outbound ) for any no. of records per batch then scope defined for this should be only - One (1) .

Note - we have to manually set Scope for batch, if there is need to set batch other than 200 . But , scope should only be in range of 1- 199 .

Eg . for executing batch apex code for Outbound callouts with scope defined as One .
Batch_closed_ca batchapex = new Batch_closed_ca();

// Defining scope for the batch ...
id batchprocessid = Database.executebatch(batchapex,1);
system.debug('Process_ID: ' + batchprocessid);
Ameed UddinAmeed Uddin

i have a created a callout class and in it a function to get response from an end point say "https://www.eventbriteapi.com/v3/events/search/?token=LRZXU32PCQYH2ZH5PQQC&categories=103&expand=venue%2Corganizer&page=1"

We can see that at this endpoint they have implemeted pagination.So first time you hit this url you get data for first page and a page count. ie you have to make a callout again iteratively so as to get the data for the next page and then subesquently for other pages.

Now I need to know how to implemet the same as we have a governer limit of 10 callouts per transaction and I need to get the entire data in salesforce in one go.

Any sample code will be of great help as I am quite new to SF paltform.