I have an apex class that is executed in parallel by calling Database.executeBatch()
in a loop, where each instance processes a chunk of a dataset.
After all the jobs that were executed finish I need to execute some apex.
My initial thought is to query the AsyncApexJob
records in the finish
method of each batch instance, then kick off the final apex when no other jobs exist.
I'm worried there's an edge case with the last 2 jobs calling finish
at the same time and not calling the final apex action.
Is there a better way to know when all submitted jobs have finished?