There are 1200 records/accounts in the 3rd party cloud based billing system. I need to update the records in SFDC.

Now for each record, I need to do 2 callouts. I am thinking to write batch apex for the same. My understanding is that I need to set the batch size as '1' and make 2 http callouts per execution context (we have a limit of 10 callouts per execution context), parse the JSON response and upsert the data in SFDC.

So in total there would be 2400 callouts each time my batch runs. I need to run this batch every 2 - 3 hours during the business hours.

Does 'Batch Apex' suffice for this kind of requirement. Thoughts / Ideas ??

1 Answer 1


The batch size you can keep is 5 .As thats the maximum no of calls allowed per batch context is 10.

Small example:

 String query = 'Select Contact.FirstName,Contact.MobilePhone,Contact.Email,Contact.Default_Channel__c,Campaign.Email_Subject__c,Campaign.Text_Message__c,ContactId,Campaign.Email_Template__r.HtmlContent__c,Campaign.Account__r.Site_ID__c,Campaign.Account__r.SMS_Phone_Number__c,CampaignId From CampaignMember where CampaignId='+'\''+campId+'\'';
             SendEmailBatch obj = new SendEmailBatch(query); 
             database.executebatch(obj, 5); //Assuming 2 callouts in each context

Remember to mention Allowcallouts=true on batch context.

global class  SendEmailBatch implements Database.Batchable<sObject>,Database.AllowsCallouts {


There will be 240 batches if you keep batch size as 5 .(Assuming 2 per each record ).Only issue i see is if in case the current batch of 240 batches in 3 hours dont get over and you start another job then there is a possibility that you may queue more than 5 batches in system and hit governor limit .

If there is a way these records can be accessed in bulk from external system then i would explore that and in case this option is not available i would increase the window so as to make sure the next job(each job with 240 batches) starts after first job gets over.

  • Thanks Mohith. I think there will be 1200 batches, as I need to process one record at a time with 2 callouts for each record/account. Further thoughts ? Commented Aug 18, 2013 at 6:35
  • you can pass query and keep batch size as 5 .There will be 240 batches as per me .limit is of 10 in context. Commented Aug 18, 2013 at 6:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .