How to get the batch status using Apex in Salesforce?

How to get the batch status using Apex in Salesforce?

Sample Code:

Batch_Class_Name obj = new Batch_Class_Name();
Id batchId = Database.executeBatch();


AsyncApexJob job = [SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors FROM AsyncApexJob WHERE ID =: batchId];

Cheers!!!

Leave a Reply