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
Mak OneMak One 

I want to insert records in Salesforce by calling Web Services of external application. How to take care of limits?

I want to get data from external system by calling it's Web Service. And insert records in Salesforce with that data.
Now, the problem is there is limit of 10 Web Service call outs per Transaction. But in my scenario I have to create a Scheulable which will do too many call outs. (say 500 Web Service call outs). Like for each Account I want to get Billing Details for that account. So, in request I will be sending Account Details and in response I will be getting Billing Details for that account. So, if there are 500 accounts for which I have to get billing details then I have to call Web Service 500 times.
It has to be programmatic, not through CSV file, Data Loader, etc.

Is it even doable?
Chris GaryChris Gary
Yes, this is doable.  You can Create your class and inherit the Batchable and Scheduleable interface.  In your Schedule.start method, run your Batch execute with a Batch of 1. The Batchable.start method will have your query, which will determine the number of web service calls you need to make (I'm assuming that you can figure out what data you need to get by querying Salesforce), and the Batch will run 1 record at a time (and each time it runs, it will be in a separate context), so you won't hit Web Service Callout limits.  Just make sure that no other instances of your scheduled job kick up while your initialone is still running.  You can do this by inspecting either the Crontab object for running jobs, or by architecting your data pulls in such a way as to not step on each other when attempting to run. Hope this helps.
Chris GaryChris Gary
Please mark the answer that helps you as solved if your question was answered, or please provide more information to get your question answered.  Thanks!