I have an Apex class that implements the
Queueable interface which is used to remove custom objects attached to a set of
Account Ids, and then inserts new custom objects to replace them.
The volume can be quite high (more than 10k removed, more than 10k inserted) without exceeding memory or CPU limits, so my implementation creates the
List of new objects for a set of
Account Ids, then passes the list of
Account Ids and the new custom objects to the
Queueable class through the constructor.
execute() method first finds the custom objects for the give
Account Ids and deletes 10k at a time (the DML row limit), calling itself recursively until all have been removed. It then performs the inserts in a similar way - 10k at a time - until all have been inserted.
The problem I am having is testing the
Queueable calling itself recursively as only one job can be executed in the Test context at a time. Is the only way to cover (most) of the code to refactor it so that all except the
System.enqueueJob() call is outside of the