Monitoring Batch Apex
Once we have submitted a Batch Apex job for processing, we want to be able to monitor its execution to see how it is performing. Whenever we make a call to Database.executeBatch, we are returning an Id for our AsyncApexJob sObject, which we can use to retrieve the status of the batch job through a query, as shown in the following snippet. This can be executed in the Execute Anonymous window:
Id batchJobId = Database.executeBatch(new ExampleBatch());
AsyncApexJob apexJob = [SELECT Id, Status, JobItemsProcessed,
TotalJobItems, NumberOfErrors FROM AsyncApexJob WHERE Id =
:batchJobId];
System.debug('Job has status of ' + apexJob.Status + ' and has
processed ' + apexJob.JobItemsProcessed + '/' + apexJob.
TotalJobItems + ' with ' + apexJob.NumberOfErrors + ' errors.'); We can also monitor the batch jobs we have submitted in the...