SF-PD2 Advanced Developer Fundamentals Practice Question
A developer has written an Apex class that queries for a large number of records and processes them in a loop. The developer notices that the transaction is hitting the heap size limit. Which technique should be used to process the records in smaller batches to avoid exceeding the limit?
⚠ Common exam trap
The trap here is assuming that asynchronous methods like @future or recursive triggers can solve heap size issues, but only batch Apex provides true chunking with separate governor limits per batch.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use Database.executeBatch to implement a batch Apex class that processes records in batches.
Batch Apex is specifically designed to handle large data volumes by splitting the work into manageable chunks. Each batch executes in its own transaction, so heap size and other governor limits apply per batch rather than to the entire data set. Implementing Database.Batchable and invoking it with Database.executeBatch allows the developer to process records efficiently without exceeding limits.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Use Database.executeBatch to implement a batch Apex class that processes records in batches.
Why this is correct
Batch Apex is designed to process large data sets in smaller chunks, each within its own transaction and governor limits. By implementing the Database.Batchable interface and using Database.executeBatch, the developer can process records in batches, significantly reducing heap size per transaction and avoiding limit exceptions.
- ✗
Use a SOQL query with a LIMIT clause and process records in chunks using a recursive trigger.
Why it's wrong here
Using a LIMIT clause with a recursive trigger is not a recommended pattern for batch processing. Recursive triggers can lead to unexpected execution and governor limit issues. This approach does not reliably reduce heap size because the trigger may still process many records, and recursion can cause additional problems.
- ✗
Use a for loop with a SOQL query inside to retrieve records one at a time.
Why it's wrong here
Performing a SOQL query inside a loop is a well-known anti-pattern that quickly hits governor limits on the number of queries. It does not reduce heap size effectively because each query still consumes resources, and the overhead of many queries can cause the transaction to fail. This approach is inefficient and not scalable.
- ✗
Use the @future annotation to process records asynchronously in a single method.
Why it's wrong here
The @future annotation allows asynchronous execution, but it does not inherently batch records. A single @future method can still process a large number of records and hit heap size limits. Additionally, @future methods have limits on the number of calls and cannot be chained, making it unsuitable for large-scale batch processing.
About these practice questions
One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Salesforce exam blueprint
This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.