LogoRazy
batch apexsalesforceapex

Batch Apex FAQs

Jan 27, 2026Abhishek Razy5 min read

**What is Batch Apex?**

Batch Apex is a way to process a large number of records (over 50,000) in chunks, or "batches," to avoid hitting governor limits. It's designed for asynchronous processing.

**What are the governing limits?**

The main limits are the batch size (the number of records processed per execute method call, which can be up to 2,000) and the total number of records processed in the entire job.

**What is the interface?**

The primary interface is Database.Batchable.

**What is Database.Batchable Interface?**

It's the interface that an Apex class must implement to be a Batch Apex job. It defines three methods: start, execute, and finish.

**What are all the methods we have in this interface?**

The methods are:

start(): Gathers the records to be processed.

execute(): Processes one batch of records.

finish(): Performs post-processing tasks after all batches are complete.

**What is Iterable Interface?**

Iterable is an alternative to Database.queryLocator for the start() method. It allows you to create a custom, in-memory collection of records to be processed.

**What is Database.queryLocator?**

A queryLocator is used in the start() method to query up to 50 million records. It bypasses the standard governor limit of 50,000 records for SOQL queries.

**What is the purpose of the start method?**

The start method is used to collect the records that will be processed by the batch job.

**What is Database.BatchableContext?**

It's an object passed to the start, execute, and finish methods that holds the ID of the batch job.

**What is the execute method?**

The execute method processes a single batch of records. The business logic for the batch job is contained within this method.

**How many times is the execute method called?**

It is called once for each batch of records returned by the start method.

**What are all the parameters we have in execute?**

It takes two parameters: Database.BatchableContext and a list of records to be processed.

**Can we call a future method in the execute?**

No, you cannot call a future method from the execute method of a batch class.

**Can we call an email program in batch?**

Yes, you can send emails from a batch class.

**Can we call callouts in the execute?**

Yes, but you must specify Database.AllowsCallouts when executing the batch job.

**What is the finish method?**

The finish method is called once after all batches have been processed. It's used for sending confirmation emails or performing other post-processing tasks.

**Can we call a future in the finish?**

Yes, you can call a future method from the finish method.

**Can we call callouts in finish?**

Yes, if Database.AllowsCallouts is specified.

**Can we call another batch in finish?**

Yes, you can chain another batch job from the finish method.

**What is batch serialization?**

Batch serialization is the process of converting the state of a batch class instance into a format that can be stored and transmitted, allowing Salesforce to persist and manage the job.

**Can we declare the future method in batch apex?**

No, a future method is defined using the @future annotation. You can call one from a batch class's finish method, but not declare one inside it.

**What is Database.AllowCallouts?**

It's an optional interface you can implement to enable callouts from the execute and finish methods of a batch class.

**How many batch jobs can be added at a time?**

You can have up to five active batch jobs running at any one time.

**What are the best practices you have followed in batch apex?**

Keep the batch size small (e.g., 200) to avoid hitting limits.

Avoid complex logic in the start method.

Handle any exceptions gracefully.

Use Database.queryLocator for large data sets.

**How to write a test class for batch apex?**

You use Test.startTest() and Test.stopTest() to ensure the batch job runs synchronously within the test method, allowing you to assert the results.

**What is Test.startTest() and Test.stopTest()?**

These methods define a block of code in a test class that has a fresh set of governor limits. Test.stopTest() runs all asynchronous processes, including batch jobs, to completion.

**According to Spring 25, any update in the batch (flex concept)?**

This refers to Flex Queue for Batch Apex. It changed how batch jobs are queued, allowing up to 100 queued jobs at a time, with the system prioritizing them for execution.

**Give me some better scenario you have implemented in your Project and why you have chosen batch for this?**

A great scenario is a monthly data cleanup process. For example, deleting old, unused records or archiving data. Batch Apex is the ideal choice because it can handle the large volume of records without hitting governor limits.

**What is the default size of the batch?**

The default batch size is 200.

**********What is the maximum and minimum size of the batch?**********

The minimum size is 1, and the maximum is 2000.

**What is the maximum number of records that can be fetched using the Batch start method?**

Using Database.queryLocator, you can fetch up to 50 million records.

**How many callouts can be called from each batch apex?**

You can make up to 10 callouts from a single execute method call.

**What is AsyncApexJob**

AsyncApexJob is a standard object that stores information about the state of all asynchronous Apex jobs, including Batch Apex.

Comments (0)

Loading comments...

Leave a Reply