Salesforce Certified Application Architect

Wednesday 1 April 2015

When you get the error “Non-selective query against large object type”? how to resolve it

When you get the error “Non-selective query against large object type”? how to resolve it


Whenever an object has greater than 100K records any query on that object must be “selective”. For a query to be selective it must have enough indexed filters (where clauses) so that less than 10% of the records (in our example 10K) are returned before applying the limit statement

Below are some good examples of selective queries for a little inspiration.
Example 1
SELECT Id FROM Contact WHERE Id In ('00Q6000000nuyL2EAI','00Q6000000iyBBhEAM','00Q6000000j007MEAQ')
Example 2
SELECT Id FROM Lead WHERE Email != ' '
This one is a trick. Email is an indexed field on Lead but if you look at my WHERE clause, this is going to return darn near all the Leads. So, I didn't reduce this record set by much and thus this reverts to a 'non-selective' query. 
SELECT Id FROM Lead WHERE Email != ' ' and Status = 'Open' and Owner Id in  ('005d0000001btXoAAI', '005d0000002X1AqAAK') 

No comments:

Post a Comment

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...