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