You need to sign in to do that
Don't have an account?
Ehsan 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.
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.
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
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?