I have code that must be called as @future
as it requires all the resources one can get. The only problem is that in 1% of the cases this code is called from a Batch and therefore fails with
System.AsyncException: Future method cannot be called from a future or batch method
Is the new Queueable
interface a solution to this? Meaning can I convert this @future
into an Apex class that implements Queueable
and fix this problem?
Or would I need to convert my calling Batch into a series of Queueable
calls?
What I already tried:
I tried to call multiple Queueable
's (one per record) from the Batch and ran into
Too many queueable jobs added to the queue: 2
When I instead passed in a List<Id>
and let the Queueable
to iterate through this list be restarting itsself for remaining records in its execute()
method I got
Maximum stack depth has been reached.