+ Start a Discussion
Neha RNeha R 

Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.

We have a query that is giving the exception -
System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null)

The query is - SELECT GUP_GUID__C,OWNERID,CORPORATE__C,ECP_NAME__C,NAME,ACCOUNT__C FROM ECP__c WHERE OwnerId IN :ownerIds AND GUP_GUID__c IN :gupGuids AND Status__c = 'Active' AND Corporate__r.Status__c = 'Active' ORDER BY WCSS_Create_Date__c DESC LIMIT 50000

Both sets used in query ownerids and gupguids are not empty and do not have null values. The query with the ids substituted in query editor gives 0 results so the return size of query is also no concern. The query has Owner id in the where clause which is automatically indexed by salesforce.

Code run from anonymous window runs without exception, i am stumped, not sure why is this query failing then?