Defination of Batch Apex
Batch Apex in Salesforce is a way to process large amounts of records asynchronously. It allows you to break down operations into smaller, manageable chunks instead of hitting governor limits when dealing with bulk data.
Key future of Batch Apex-
Handles Large Data Volumes – Can process up to 50 million records.
Runs Asynchronously – Runs in the background without blocking user interactions.
Efficiently Bypasses Governor Limits – Executes in small batches (default 200 records per batch), reducing limits on CPU time, queries, and DML operations.
Supports Callouts – Can make external web service calls if
Database.AllowsCallouts
is implemented.Can be Scheduled – Works with
System.scheduleBatch()
to automate execution.
Basic Structure of Batch Apex
To implement Batch Apex, you must implement the Database.Batchable
interface, which has three methods:
start
– Gathers the records to be processed.execute
– Processes each batch of records.finish
– Performs final actions like logging or sending emails.