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

11:20 AM

 

 Exception:   

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

 

Root Cause:

This exception is caused when the SOQL query is against on object with more than 200000 records and the query is not efficient. The query takes a longer time to execute and hence the exception.

Ex: Select Name,Email from Contact 

Ex: Select Name,Email from Contact where Status__c != NULL (Status__c is a custom non indexed field)


Resolution:

Option 1:

Make the query selective. Use Indexed fields when making the query selective, for example Id, CreatedDate, LastModifiedDate  etc are indexed.

Ex: Select Name,Email from Contact where LastModifiedDate  >=  LAST_N_DAYS:30

To find the indexed fields, use the object manager under setup

 

 Option 2:

If you need a custom field to be indexed, Salesforce support could add a custom index for you. Create a support case with Salesforce to get your custom index created. 

When the custom index is created, make your query selective using the custom indexed field.

 

 

0 comments

Stats