System.QueryException: Non-selective query against large object type: meaning and how to fix it
Quick answer
System.QueryException: Non-selective query against large object type: A query in a trigger filters on fields that are not selective on an object with a large number of records, so Salesforce refuses to run it. Start with: Add a filter on an indexed field that narrows the results to a small share of records.
Typical message: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Cause
A query in a trigger filters on fields that are not selective on an object with a large number of records, so Salesforce refuses to run it.
How to fix System.QueryException: Non-selective query against large object type
- Add a filter on an indexed field that narrows the results to a small share of records.
- Avoid filtering on formula fields or fields with mostly the same value.
- Ask Salesforce Support about a custom index when the filter is correct but still not selective.
Have a different message? Paste it into the error decoder, which matches it against 45 common Salesforce errors in your browser.
Frequently asked questions
What does System.QueryException: Non-selective query against large object type mean in Salesforce?
A query in a trigger filters on fields that are not selective on an object with a large number of records, so Salesforce refuses to run it.
How do I fix System.QueryException: Non-selective query against large object type?
1. Add a filter on an indexed field that narrows the results to a small share of records. 2. Avoid filtering on formula fields or fields with mostly the same value. 3. Ask Salesforce Support about a custom index when the filter is correct but still not selective.
More SOQL and queries errors
SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Message text varies slightly by release and context, so confirm against the official page before relying on it.