function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Niraj Singh 28Niraj Singh 28 

what is Jobid and Batch id, how can i get these?

Hello All,
I am new in salesforce development and want to know two things JobId and BatchId, and alos want to track my batch means how many record got to fails from processing.


Thanking you
Niraj Singh
Raj VakatiRaj Vakati
When the job is complete, the finish method performs a query on the AsyncApexJob object (a table that lists information about batch jobs) to get the status of the job and you can get the Batch Job ID by using the getJobId from BatchableContext

You will get the Batch job id like this 
 
global void finish(Database.BatchableContext bc){
        System.debug(recordsProcessed + ' records processed. Shazam!');
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, 
            JobItemsProcessed,
            TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id = :bc.getJobId()];
      
}



In Salesforce, records in the 'AsyncApexJob' table represents Apex jobs to run asynchronously when resources are available. Examples of these asynchronous Apex jobs include Future Methods, Queueable Apex, Batch Apex and Scheduled Apex. If we examine the SOAP API guide for the 'AsyncApexJob' object, we see these mentioned asynchronous jobs represented under the 'JobType' field, however we also observe a number of other job types such as 'ApexToken', 'TestWorker' and 'TestRequest'. Whilst standard asynchronous jobs such as the aforementioned Future, Queueable, Batch and Scheduled are widely documented, what about the others? 

https://help.salesforce.com/articleView?id=000228389&type=1


As per the documentation on the 'AsyncApexJob' object, under the 'JobType' field there are currently nine types of asynchronous Apex jobs, these are as follows:
  • Future
  • SharingRecalculation
  • ScheduledApex
  • BatchApex
  • BatchApexWorker
  • TestRequest
  • TestWorker
  • ApexToken
  • Queueable
AsyncApexJob jobInfo = [SELECT Status, NumberOfErrors
    FROM AsyncApexJob WHERE Id = :jobID];