We have a requirement of operating on data in present in different objects. The total record count (of all objects) ~ 50 millions (some objects holding ~20 millions records alone). So we have considered the option of handling it via batch apex.
The logic is:
- Create a List (say
objectsList
) of String which will hold the object names. - A method will start batch execution from For loop. Batch apex will identify the object by the integer passed and start operating on that object.
Something as follows:
for(integer i = 0; i< objectList.size(); i++){
RandomBatch bch = new RandomBatch(i);
Database.executeBatch(bch,2000);
}
Is this feasible and practical? From what I read, flex queue has capacity of holding 100 jobs in queued state. We don't have more than 20 objects to cover (so 20 batches will be executed). Can flex queue hold jobs for over 2 days (since objects holding ~20 millions records are going to take time to complete). And is it even acceptable to execute batch apex from For loop? There's nothing going to be in finish()
method (apart from mailing us the error messages if any).