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
Ehsan DevEhsan Dev 

HTTP Callout iterate

I am developing an app that can itirate through all the possible serial numbers with XXX-XXXXXXXX format (000-00000000 to 999-99999999) through an HTTP callout on a regular basis to keep the relative internal data up-to-date according the the external system. The external callout URL allows calling up to 20 serial numbers per call and looks like this for calling 2 sample serial number:
https://SAMPLE.com/v1/license?serialnumber_productlinecode=321-99889631,365-99123632
I was able to write the Apex code for a single call out. However, I need help to figure out what is the best way to itirate through all the possible combination of numbers in XXX-XXXXXXXX format regularly (e.g. daily basis) and avoid hitting the callout and CPU limits. Please advise.
 
pconpcon

What you are trying to do is probaly not best solved by the way you are trying to do it.  It would be better to push data into Salesforce from your external system (when serial numbered items change or are added).  With that being said, you are likely to hit limits very fast since you are iterating through 99999999999 numbers with 4999999999.95 callouts which will take a minimum of 49999999.9995 batches of apex (assuming you can get under the CPU limit threshold.  As far as keeping track of what number I was on, I would probably either write it to a custom sObject that had my current number or store it in a custom setting that gets updated at the end of the transaction  You could use something like relax [2] to schedule the jobs, but assuming that each takes the time limit (60s), my math shows that it would still take you ~95 years to complete each pass.

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_timeouts.htm
[2] https://github.com/zachelrath/Relax
Ehsan DevEhsan Dev
pcon thank you for your description. Unfortunately, we do not have much control over that external system available calls. It only gives up up to 20 serial numbers per call. There is no call available to get the changed or added serial numbers. Also, not all of those possible numbers actually exist in that external system; about 30,000 of them actually are real serial numbers, but this was the way that I could imagine to find changes or added ones.
The other way that I can think of is to use a middle app to do the calls and get the responses , then make it available as oData to be uses as external object in Salesforce. What do you think about this idea?
pconpcon
That would be one way to do it however the Lightning connector is not a cheap thing to implement.  It would probably be cheaper to either work with whomever owns the endpoint to export the data to Salesforce (or some intermediary system) or to create 3rd party system that does your query and push to Salesforce.  You can easily mark the serial number field as an external identifier and that will help in updating the data.