function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Preetham 345 SFDCPreetham 345 SFDC 

ApexTrigger: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter

I am getting this error  in the ApexTrigger in the production environment , And i am also pasting the query  where i am  getting this error 

Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id
                                                            ,AccountId
                                                            from Contact
                                                             where AccountId in :acctIds and Name != null and Contact_Type__c includes ('Technical Contact')]);

ApexTrigger: execution of AfterUpdate  caused by: 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) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

I have searched so many blogs in google , what ever they suggested in that blog are there in this query , eventhough i dont know why i am getting this error.
If any one have any idea on this , please Kindly help me over this error.


Vishant ShahVishant Shah
if Name is a string field, try using != '' instead of null, i had a similar issue but not over such a large number of records.. give it a shot cant promise it would work
srinu_SFDCsrinu_SFDC
Hi Pritam,

        The problem is with Name or Contact_Type_c conditions in query(more probably with Name). One way to tackle this is remove those from query and filter irrelavant records in code. See if it can help?
Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>();
for(Contact contact : [select Id ,AccountId,Name, Contact_Type__c  from Contact where AccountId in :acctIds] ){
     if(contact.Name != null && contact.Contact_Type__c != 'Technical Contact')
	continue;
     else
        contactsForAccounts.put(contact.ID, contact);

}

Thanks,
Y.Srinivas 
Preetham 345 SFDCPreetham 345 SFDC
Yeah Srinivas , Thank you for your quick reply, got your point , i will check it and let you know