0

I have a series of regular maintenance batch jobs that aren't dependent on each other and are triggered by a user.

For example

  1. Clean up accounts
  2. Clean up contacts
  3. Clean up leads

The list of items that need to be cleaned up is maintained in a separate custom object. All of this makes sense to enqueue independent batch jobs.

At the end of the execution of the various cleanup jobs the custom object itself needs to be updated that the entire run was successful. I'm unclear on how I can monitor completion of multiple jobs. Some sort of meta job that polls for completion of the cleanup jobs and executes when they're marked as successful.

2 Answers 2

0

This can be easily achieved using the finish method of the implemented batch class, you can update the custom object as required.

You need to factor in exceptions that can occur during the clean-up job. For that, I would suggest tracking the status of the Job querying the AsyncApexJob. You can obtain the JobId from BacthaleContext passed as a parameter in the finish method.

0

To track the exceptions vs successfully processed records during each batch transaction, you will have to implement stateful batch (refer to Using State in Batch Apex). In a stateful batch implementation, you can use an instance collection variable to track the success vs error records. This instance variable can then be used by the finish method where you will have to write some code to clean-up the processed custom object records (or mark them as processed and clean them up later via another async apex).

So, the clean-up will have to be taken care at the individual apex batch implementation. Monitoring the batch apex status for completion won't help you much because it will give you the job completion status, but not details of the records that ran into exception during batch execution.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .