2

I m getting the following error in a trigger.

Error:Apex trigger ContactSumTrigger caused an unexpected exception, contact your administrator: ContactSumTrigger: 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): Trigger.ContactSumTrigger: line 95, column 1

The code at that place is :

 List<AggregateResult> ContactCountByAcc = 
       [SELECT AccountId Acct, count(Id) RecCount 
        FROM Contact 
        WHERE AccountId in :AccIds AND GE_HQ_CONTACT_STATUS__c != 'Inactive' 
        GROUP BY AccountId ];

AccIds do not contain any null values.

  • How many items are in AccIds? – Jagular Jul 2 '14 at 13:48
6

The error message is quite detailed, the query needs to be more selective so that less data is returned. There's a lot of into on that online, and an answer on how to solve this can't really be given without detailed knowledge of your object, its fields and specific query use case.

Yet, in general you should not use != in soql because it can't utilize any table indexes and will require a full table scan. To start optimizing your query, consider changing

GE_HQ_CONTACT_STATUS__c != 'Inactive' 

into

GE_HQ_CONTACT_STATUS__c IN ('Active','Other Status','Yet Another Status')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.