Suggested answer

Batch Apex (implementing Database.Batchable<sObject>) processes large data sets by breaking them into chunks. Three required methods:

1. start(): Returns a QueryLocator (SOQL query up to 50M rows) or an Iterable. Called once at the beginning.
2. execute(): Processes one batch chunk (default 200 records, configurable 1–2000). Called once per chunk. Each execute() runs in its own transaction with fresh governor limits.
3. finish(): Called once after all batches complete. Used for post-processing (email notifications, chaining another job). Database.Stateful: Implement this interface to maintain instance variable state across execute() chunks (e.g., running totals). Without it, variables are reset between chunks. Execution: Database.executeBatch(new MyBatch(), 200);

Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.

Community comments (0)

No comments yet.

Sign in or create a free account to add a comment. Comments are moderated before they appear.

Plain text only, 3–2000 characters. A moderator reviews every comment before it is published.