Development questions
What is a Selective SOQL Query, how does the Query Plan Tool work, and what are the indexing thresholds (30% of first 1M records, 15% after)?
A query is selective when its filter uses an indexed field and returns less than a threshold of the object's records, so the optimizer can use the index instead of a full table scan. Non-selective queries on large objects (over ~100,000 records) can fail in triggers with Non-selective query against large object type.
Thresholds (standard index): roughly 30% of the first 1 million records and 15% after, up to a cap (custom index: 10% / 5%).
Use the Query Plan Tool in the Developer Console: it shows cost per plan; a cost below 1 means selective (index is used).
soqlperformanceselectivityindexes
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?