SF-PD2 Performance Practice Question
A developer is building a batch Apex class to process 1 million records. The class implements Database.Batchable and uses a SOQL query in the start method. During testing, the developer notices that the batch job fails with a 'First error: Exceeded maximum number of SOQL queries' error. What is the most likely cause and how can it be resolved?
⚠ Common exam trap
The trap here is focusing on the start method or batch size, when the real issue is a query inside a loop in the execute method that exceeds the SOQL query limit.
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
✓
The execute method contains a SOQL query inside a loop; move it outside the loop and use a Map.
The most likely cause is a SOQL query inside a loop in the execute method, which quickly exceeds the 200 SOQL query limit per transaction. Moving the query outside the loop and using a Map to correlate records resolves the issue by reducing the number of queries to one per batch transaction. The other options do not address the root cause.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
The execute method contains a SOQL query inside a loop; move it outside the loop and use a Map.
Why this is correct
Batch Apex allows up to 200 SOQL queries per transaction. If the execute method queries inside a loop, it can quickly exceed this limit. Moving the query outside the loop and using a Map to correlate records is the standard fix. This bulkifies the code and prevents governor limit errors.
- ✗
The start method uses a QueryLocator; switch to an Iterable to avoid query limits.
Why it's wrong here
Using a QueryLocator or Iterable in the start method does not affect the number of SOQL queries in the execute method. The error is likely due to queries in the execute method, not the start method. Switching to Iterable would not resolve the issue and may complicate the code.
- ✗
The query in the start method is not selective; add a WHERE clause to filter records.
Why it's wrong here
A non-selective query can cause performance issues but typically results in a 'Non-selective query' error, not a SOQL query limit error. While adding a WHERE clause is good practice, it does not directly address the query limit issue, which is about the number of queries, not selectivity.
- ✗
The batch size is too large; reduce the batch size to 1 to avoid query limits.
Why it's wrong here
Reducing the batch size to 1 would increase the number of transactions and may actually worsen performance, as each transaction has its own limits. It does not address the root cause, which is likely a query inside a loop. The default batch size is 200, and reducing it is not a solution for query limits.
Visual reference
About these practice questions
Courseiva writes every SF-PD2 question from scratch — 226 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.