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
grigri9grigri9 

how do I split Apex into multiple transactions to avoid callout governor limits?

We have an external license key server that we use to fill in a license key field on Assets. The license key server is only able to return one license key at a time. The getLicenseKey function is called from a trigger and iterates through the Assets, returning a license key for each. However, if we run the trigger for anymore than 10 Assets we hit the 10 callouts governor limit.

 

Is there any way to avoid this governor limit by splitting the code into multiple Apex transactions somehow? 

k2sfdevk2sfdev

I guess you can try scheduled tasks

 

assign 10 licences for each run

sfdcfoxsfdcfox
You could also use @future to call them later; this would allow you to query 100 keys per call (10 @future calls having 10 callouts each). If you need more than that, you're probably in trouble, as I can't think of a way to expand it much beyond that. As a final option, you could consider an outside hosted relay to support the bulkification of the callouts. Like I said, a last resort... it would involve some outside hosting, which would cost some extra funds.
grigri9grigri9

This is what we ended up doing. We still sometimes hit the limits but it is infrequent enough that the customer is ok with re-running manually once in a while. I can't wait till scheduled apex comes out.