SalesforceWizard

Batch Apex interview questions

Batch Apex questions get practical fast: how many records, what scope size, what happens when one chunk fails. These answers stay close to what you would actually build.

0 of 14 reviewed
On this page (7 sections)Interview questionsCommon Mistakes Candidates MakeRelated Batch Apex Interview QuestionsMore Batch Apex questionsFrequently Asked Questions about Batch Apex InterviewsRelated CertificationsRelated Resources

Recently updated: May 2026

Batch Apex still comes up in almost every PD2-level interview because companies routinely process millions of records: recalculations, data migrations, periodic syncs. The questions below are the ones actually being asked in 2025-26 senior developer rounds.

01

What is Batch Apex and when do you actually need it?

Batch Apex

Batch Apex is for processing large data volumes (50K+ records) that exceed synchronous governor limits. You implement Database.Batchable<SObject> with start(), execute(), and finish() methods. Salesforce splits the data into chunks (default 200) and processes each chunk in its own transaction with fresh limits. Real example: nightly recalculation of customer scores across 5 million Accounts.

02

Walk through the three methods of Database.Batchable

Batch Apex

start() returns the records to process: either a QueryLocator (for SOQL) or an Iterable (for custom collections). execute() takes a chunk of records and does the actual work: DML, callouts (with Database.AllowsCallouts), business logic. finish() runs once at the end, perfect for sending a summary email, chaining the next batch, or kicking off a queueable.

03

QueryLocator vs Iterable; which to use?

Batch Apex

QueryLocator can return up to 50 million records and uses standard SOQL. Iterable is limited to 50K records but lets you build the collection any way you want, including from REST callouts. 95% of the time use QueryLocator. Use Iterable only when the records aren't queryable directly (external data, complex filters).

04

How do you choose batch size?

Batch Apex

Default is 200, max is 2000. Lower batch size if execute() is heavy (callouts, complex logic): say 50 for callouts, 100 for DML-heavy work. Increase to 500-1000 for simple field updates with no callouts. The trick is to keep one execute() under all governor limits comfortably, leaving headroom for safety.

05

What is Database.Stateful and when do you use it?

Batch Apex

By default, instance variables reset between execute() calls. Database.Stateful preserves them across batches: useful for running totals, error collections, or tracking how many records were processed. Caveat: it can hurt performance if the state grows large, so keep it minimal.

06

How do you make HTTP callouts from Batch Apex?

Batch Apex

Implement Database.AllowsCallouts on the class. Salesforce gives one callout per execute() chunk by default: increase by reducing batch size. Wrap callouts in try/catch, log failures to a custom error object, and never let one bad record stop the whole job: collect errors and report in finish().

07

How do you chain Batch jobs?

Batch Apex

From finish(), call Database.executeBatch(new NextJob()). This is the standard chaining pattern. Watch the 5-active-batch-job limit: chained jobs count too. If you need parallelism, use Queueable Apex which has separate limits.

08

How do you write a test class for Batch Apex?

Batch Apex

Insert test data, then Test.startTest(), Database.executeBatch(new MyBatch(), 200), Test.stopTest(). Test.stopTest forces the batch to complete synchronously. Then assert the results. Always test with at least 200 records to catch bulkification bugs.

09

What governor limits apply to Batch Apex?

Batch Apex

Each execute() chunk gets its own limits: 100 SOQL, 150 DML statements, 10K DML rows, 60-second CPU. You also have org-wide limits: 5 active/queued batch jobs, 100 scheduled Apex jobs. Total records returned by start() can be 50M for QueryLocator, 50K for Iterable.

10

Real interview scenario: rebuild a denormalised field across millions of records

Batch Apex

Build a Batch class with start() returning all parents via QueryLocator, execute() processing 200 parents per chunk: fetch related children, calculate the value, update parent. finish() emails a completion report. Schedule it nightly via Schedulable. Add Database.Stateful to count records processed and errors. Test with 200+ records.

Common Mistakes Candidates Make

Wrong batch size. Default 200 isn't always right: tune for the workload.

No error logging. Silent failures in execute() are the #1 production issue.

Forgetting Database.AllowsCallouts. Callouts will throw a runtime exception otherwise.

Not testing with 200+ records. Bulkification bugs only show with bulk data.

Strengthen your preparation by exploring related question banks in the same topic cluster. Each guide covers a unique angle of batch apex interviews: pick the one closest to the role you are targeting.

More Batch Apex questions

11

If one record in a batch scope fails, what happens to the others?

Intermediate

With update scope;, one failure rolls back the whole chunk (for example 200 records), but other chunks still run because each execute call is its own transaction. Use Database.update(scope, false) to save the good records and log the failed ones from the SaveResult list.

12

What statuses can a batch job have?

Beginner

In AsyncApexJob you will see Holding (waiting in the flex queue), Queued, Preparing (the start method is running), Processing, Completed, Failed and Aborted. Up to 100 jobs can wait in the flex queue, and five batch jobs can be queued or active at once.

13

How do you stop a running batch job?

Beginner

Abort it from Setup, Apex Jobs, or with System.abortJob(jobId). The chunk currently running finishes; the remaining chunks do not run.

14

How do you report errors from a batch job to the team?

Intermediate

Collect errors in a Database.Stateful variable or write them to a custom log object in execute, then in finish send one summary email or post a notification with the counts and a link to the log. The finish method can also query AsyncApexJob for NumberOfErrors.

Frequently Asked Questions about Batch Apex Interviews

Difference between Batch and Queueable?

Batch processes large datasets in chunks. Queueable runs as a single async job with full DML/SOQL limits but no chunking. Use Batch for volume, Queueable for chained logic.

Can a Batch job fail silently?

Yes. If execute() throws and isn't caught, that one chunk fails but the job continues. Always log errors in execute().

How many batch jobs can run concurrently?

5 active or queued at any time per org. Hitting that limit queues the rest.

Can I call Batch Apex from a Flow?

Yes via an @InvocableMethod that calls Database.executeBatch.

Is Batch Apex still relevant in 2026?

Absolutely, for million-record operations there is still no better tool in the platform.

Batch Apex is heavily tested in PD1 and PD2. See our certification guides.

Chat on WhatsApp