Development questions
Which fields are indexed by default in Salesforce, and what makes a SOQL filter non-selective (e.g., !=, NOT LIKE '%abc', leading wildcards, formula fields)?
Indexed by default: Id, Name, OwnerId, CreatedDate, SystemModstamp, RecordTypeId, lookup and master-detail fields, unique fields, external Id fields (and fields with a custom index requested from Support).
Things that make a filter non-selective:
- Negative operators:
!=,NOT IN,NOT LIKE,EXCLUDES - Leading wildcards:
LIKE '%abc' - Filtering on null:
Field = null(often) - Formula fields (non-deterministic/unindexed) and fields wrapped in functions
- Filters returning more than the threshold of rows
Fix by adding indexed filters, requesting custom indexes, using skinny tables, or restructuring the query.
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?