SF-PD2 Performance Practice Question
A developer is building a Lightning Web Component that needs to display a list of 200 accounts with their annual revenue, and the component's Apex controller currently executes a SOQL query inside a loop over the accounts to fetch related opportunities. Users report slow load times. What is the most effective way to improve performance?
⚠ Common exam trap
The trap here is assuming that client-side caching or asynchronous processing will fix slow initial loads, when the real issue is the inefficient query pattern inside a loop.
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 with a subquery to retrieve accounts and their related opportunities in one call, then process the results in memory.
The performance bottleneck is the N+1 query pattern: one query for accounts, then a separate query for each account's opportunities. Consolidating into a single query with a subquery eliminates the repeated database calls, reduces governor limit usage, and speeds up the component. Processing in memory is efficient because the data volume is manageable.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Increase the query batch size by using Database.getQueryLocator with a higher scope size.
Why it's wrong here
Database.getQueryLocator is designed for batch Apex and does not apply to a synchronous Lightning Web Component controller. It cannot be used to retrieve records for immediate display, and scope size is irrelevant here. This option misapplies a bulk processing tool to a UI scenario, failing to address the N+1 query problem.
- ✗
Move the SOQL query into a future method to run asynchronously, and then poll for results.
Why it's wrong here
Using a future method for a synchronous UI requirement is inappropriate because future methods cannot return data directly to the component. Polling adds complexity and latency, making the user experience worse. The performance issue stems from query inefficiency, not from synchronous execution, so asynchronous processing does not solve the root cause.
- ✓
Use a single SOQL query with a subquery to retrieve accounts and their related opportunities in one call, then process the results in memory.
Why this is correct
A single SOQL query with a subquery eliminates the N+1 query problem, drastically reducing database round trips and governor limit consumption. For 200 accounts, one query returns all related opportunity data, which can be processed in memory. This is the most efficient approach and aligns with Salesforce best practices for bulk data retrieval.
- ✗
Add a @AuraEnabled(cacheable=true) annotation to the Apex method to enable client-side caching.
Why it's wrong here
While caching can improve subsequent loads, it does not address the initial slow performance caused by multiple SOQL queries inside a loop. The annotation only caches the method result on the client, but the underlying inefficiency remains, and the first load will still be slow. It is not the primary fix for the N+1 query issue.
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.