SF-PD2 Performance Practice Question
A developer is writing an Apex trigger that updates a related object's records when a parent record is updated. The trigger currently performs a SOQL query for each child record to check if an update is needed. What is the most efficient way to optimize this trigger?
⚠ Common exam trap
The trap here is thinking that caching or asynchronous processing can fix the performance problem, when the real fix is to eliminate the per-record query by bulkifying.
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 a single SOQL query to retrieve all related child records for the parent records in the trigger, then process them in a loop.
The trigger's performance issue is caused by executing a SOQL query for each child record, which is a classic N+1 query problem. The optimal solution is to perform a single SOQL query to retrieve all necessary child records for the parent records in the trigger context. This bulkified approach minimizes database calls, respects governor limits, and improves performance.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Move the SOQL query into a helper method and call it from the trigger to improve code organization.
Why it's wrong here
Moving the query to a helper method does not change the fact that it is still executed per child record inside a loop. Code organization is good practice, but it does not address the performance issue. The query must be moved outside the loop to be bulkified.
- ✗
Set the trigger to run asynchronously using @future to avoid governor limits.
Why it's wrong here
Using @future does not solve the inefficiency of multiple SOQL queries inside the trigger. It moves the processing to a separate transaction, but the same limits apply, and it may not be suitable for triggers that need to update records synchronously. Asynchronous execution does not reduce the number of queries; it only delays them.
- ✓
Use a single SOQL query to retrieve all related child records for the parent records in the trigger, then process them in a loop.
Why this is correct
Querying all related child records in one SOQL query outside of any loop is the bulkified approach. It avoids the N+1 query problem and stays within governor limits. The trigger can then iterate over the retrieved records to perform necessary updates, ensuring efficiency and scalability.
- ✗
Use a Map to cache child records after the first query, and reuse the cached data for subsequent iterations.
Why it's wrong here
Caching after the first query still results in one query per unique parent or child, which may be many. It does not eliminate the multiple queries for different records. A single query for all relevant records is more efficient and avoids hitting the SOQL limit. Caching within a loop is not a substitute for proper bulkification.
About these practice questions
This SF-PD2 question is part of Courseiva's 226-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.