SF-PD2 Performance Practice Question
A developer is writing an Apex trigger on the Case object that updates a custom field on the Account when a Case is closed. The trigger currently performs a SOQL query to retrieve the Account for each Case in Trigger.new. The developer wants to optimize the trigger to handle bulk updates of up to 200 Cases without hitting governor limits. What is the best practice to achieve this?
⚠ Common exam trap
The trap here is thinking that using Database.query with bind variables is necessary for bulkification, when a simple static SOQL query with an IN clause is sufficient and more straightforward.
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 Accounts based on the AccountId values from Trigger.new, then use a Map to update the Accounts.
The best practice for bulkifying a trigger is to collect all necessary IDs and perform a single SOQL query to retrieve related records. Using a Map to correlate the records allows efficient updates without additional queries. This reduces the number of queries to one, well within governor limits, and ensures the trigger can handle bulk updates. The other options either cause multiple queries or are not applicable to triggers.
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 a SOQL query inside a for loop to retrieve each Account and update it immediately.
Why it's wrong here
Querying inside a for loop is a classic anti-pattern that leads to hitting the SOQL query limit (100 queries) when processing 200 Cases. It also increases CPU time and can cause the trigger to fail. This approach does not scale and should be avoided in favor of bulkified logic.
- ✗
Use a Map to store the Accounts from Trigger.new, but query the Accounts in the trigger's constructor.
Why it's wrong here
Triggers do not have a constructor; they are executed as a single unit. The concept of a constructor is not applicable. The correct approach is to query in the trigger body before the loop, not in a constructor. This option is misleading and technically incorrect for Apex triggers.
- ✓
Use a single SOQL query to retrieve all related Accounts based on the AccountId values from Trigger.new, then use a Map to update the Accounts.
Why this is correct
Collecting all AccountId values from Trigger.new and performing one SOQL query to retrieve the related Accounts is the best practice for bulkification. Using a Map to relate Accounts to Cases allows efficient updates without additional queries. This approach ensures the trigger can handle up to 200 records within governor limits, reducing the number of queries to one.
- ✗
Use a Database.query call with a bind variable for each AccountId to retrieve the Accounts in a single query.
Why it's wrong here
While using Database.query with a bind variable is possible, it is not necessary and adds complexity. A static SOQL query with a WHERE clause using the IN operator on a collection of AccountIds is simpler and more efficient. Database.query is typically used for dynamic queries, but here a static query is sufficient and easier to maintain.
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.