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
manzarmanzar 

Too Many callouts:11

Hello to Experts,

I m writing a class that is making a connection with some external restful
webservice and returns data from that webservice.
When I get data from this webservice only once it behaves properly but
when I call my main function within a loop, then the following
error is generated.

"Too many callouts:11"

Looking for expert's kind attention.
David VPDavid VP
Look at 'governor limits' in the documentation ...

Salesforce.com restricts certain operations so that 'tenants' in their multi-tenant infrastructure can not consume an unreasonable amount of resources.

Resolving your problem will come down to the fact that you can not do your outbound calls within the loop. You'll have to figure out a way to get to the information in one go ...


-David
manzarmanzar
Hi,

Thank you Mr. David VP for your reply. Can u send me some specimen
related to the use of code which make outbound call at once as u
have suggested.

Thanks in advance for your future reply.
David VPDavid VP
Check out the HTTP (RESTful) Service classes' in the Apex documentation.

There's a couple of examples there if that's what you're asking.

If you're asking on how to avoid the looping : that would depend on your use case. I know you're making outbound calls but what exactly is the reason that you need to put them in a loop ?


-David




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);