I have a scenario where I need to call an API from a
trigger that will update a few fields from the API. The
trigger is an
after insert and is setup to avoid recursion with other triggers on the same object.
Currently I am having the problem of the API (I do not control it) not being able to handle request in parallel. My current code takes an
after insert trigger, fires the first apex class with
Queueable Interface which checks for if my Oauth token is expired, if it is - request a new one from the API, if not proceed to fire the second
Queueable class which makes the request in a loop to get the fields for each of the Salesforce records. This is actually working until we start using alot of records which is necessary. Even at 1000 records split up in batches of 50 via Dataloader it seems like those are too many requests for the API.
So to avoid the problem of having multiple
Queueable calls that run in parallel, I was wondering if I should just chain the 2nd
Queueable class to itself. Would that hit the
Queueable limit of depth. Or is this just something that needs to be moved out of the