When running a SOQL (Salesforce Object Query Language) query against a Salesforce object that contains more than 200,000 records, you may receive the following error, especially when the query runs inside an Apex trigger:
"System.QueryException: Non-selective query against large object type"
This error is thrown when the Salesforce SOQL query optimizer evaluates the filters in your query and cannot identify a selective filter — a filter that uses an indexed field and is estimated to match fewer than 10% of the total records in the object. Without a selective filter, querying a large object would require a full table scan, which is not permitted inside triggers.
The Salesforce query optimizer analyzes the WHERE clause of your SOQL query. A filter is treated as selective when:
If no selective filter is found, the query is marked as non-selective and the QueryException is thrown.
If your WHERE clause filters on a custom text field (for example, Text_Field__c), enabling the External ID flag on that field creates an index, which may make the query selective.
Steps to enable External ID:
In Lightning Experience:
In Salesforce Classic:
Important: This fix only resolves the error if the filter value you are using in the WHERE clause matches fewer than 10% of the records. If the filter value is too common (for example, filtering on a Status field where most records have the same value), the query will remain non-selective even with an index.
If enabling External ID does not resolve the error, log a case with Salesforce Support. The Support team will:
000384950

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.