SF-PD2 Performance Practice Question
A developer is writing a SOQL query on a custom object with 5 million records. The query filters on a custom field that is not indexed and returns a large number of records. The query is running slowly and sometimes fails with a 'Non-selective query' error. What should the developer do to improve query performance?
⚠ Common exam trap
The trap here is thinking that limiting results or adding subqueries can fix selectivity, when the real fix is indexing the filtered field to avoid full table scans.
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
✓
Create a custom index on the custom field used in the WHERE clause.
The best solution is to create a custom index on the custom field used in the WHERE clause. This makes the query selective, allowing Salesforce to use the index to retrieve records efficiently and avoid the 'Non-selective query' error. Custom indexes are essential for optimizing queries on large custom objects.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Add a LIMIT clause to the query to reduce the number of records returned.
Why it's wrong here
Adding a LIMIT clause reduces the number of records returned but does not make the query selective. The 'Non-selective query' error occurs when the query cannot use an index and must scan a large portion of the table. LIMIT does not change the selectivity; it only caps the result size, so the error may still occur if the filter is not selective.
- ✗
Use a FOR UPDATE clause to lock the records and improve query speed.
Why it's wrong here
FOR UPDATE is used to lock records for update in a transaction, preventing other transactions from modifying them. It does not improve query performance or selectivity. In fact, it can cause contention and is not related to the 'Non-selective query' error. It should only be used when necessary for record locking.
- ✗
Use a SOQL query with a subquery to filter the records more efficiently.
Why it's wrong here
A subquery is used to retrieve child records from a related object, not to filter parent records more efficiently. Using a subquery does not make the outer query selective. The 'Non-selective query' error is about the outer query's WHERE clause not using an index, so a subquery does not address the root cause.
- ✓
Create a custom index on the custom field used in the WHERE clause.
Why this is correct
Creating a custom index on the field used in the WHERE clause makes the query selective by allowing the database to quickly locate matching records. This reduces the number of records scanned and improves performance. Salesforce allows custom indexes on custom fields, which is a standard solution for non-selective queries on large objects.
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.