Loading

Execute a Batch Apex Job from the Salesforce Developer Console

Publiceringsdatum: Jun 26, 2026
Beskrivning

Batch Apex in Salesforce is a special type of Apex class that processes large volumes of records asynchronously, dividing the work into smaller chunks called batches. Running Batch Apex from the Developer Console allows developers and administrators to manually trigger a batch job on demand — without deploying a Scheduled Apex class or using the Salesforce UI. This approach is useful for one-time data processing, testing batch job logic, or performing maintenance operations. The Apex class being executed must implement the Database.Batchable interface.

Lösning

Run Batch Apex from the Developer Console

  1. Open the Developer Console.
  2. Click Debug > Open Execute Anonymous Window.
  3. In the Execute Anonymous Window, call the Database.executeBatch() method. This method takes two arguments: a new instance of your Batch Apex class (which must implement Database.Batchable), and an optional Integer specifying the batch size — that is, how many records to process in each chunk. The default batch size is 200 records; the maximum is 2,000 records. The method returns a Job ID.

For example, to execute a batch class named RunThisBatch with a batch size of 200 records, call Database.executeBatch(new RunThisBatch(), 200). Store the returned value in a variable (e.g., batchJobId) to capture the Job ID for monitoring.

  1. Click Execute to run the code.
  2. To monitor or stop the batch job after it starts, navigate to Setup > Apex Jobs (enter "Apex Jobs" in the Quick Find box).

Note: The Job ID returned by Database.executeBatch() corresponds to an AsyncApexJob record. You can query the AsyncApexJob object using the Job ID to check the batch job's status, number of batches processed, and any errors.

Knowledge-artikelnummer

000385654

 
Laddar
Salesforce Help | Article