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
Ajosh JohnAjosh John 

execution of BeforeUpdate 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.

Morning,

I have been receiving this email stating the trigger i wrote on Accounts has to be indexed.

I have no idea on what is causing this issue.

Any help on this is apprecaited. Below is the snipet of the code and the error.

execution of BeforeUpdate
 
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)

 if(MapAccount != null && MapAccount.keySet() != null){
        list<Account> colAccounts = [select id,Client_Code__c,First_Trade__c,Reactivation_Date__c,Client_FTT__c from Account where Client_Code__c != null and Client_Code__c in : MapAccount.keySet()];
        if(!colAccounts.isEmpty()){
            for(Account objAccount : colAccounts){
                if(objAccount.Client_Code__c != null){
                    MapAccountOpt.put(objAccount.Client_Code__c,objAccount);
Prabhat Kumar12Prabhat Kumar12
This line making your query non selective.
 
Client_Code__c != null

You are already adding Client_Code__c in : MapAccount.keySet() not equal to null then there is no need to add 
Client_Code__c != null. You need to remove this in order to make your query selective.
 
Ajosh JohnAjosh John
Thanks Prabhat! but I still get the same exception. I made the changes you wanted me to. See below for the code. Any help on this is really apprecaited.

if(MapAccount != null && MapAccount.keySet() != null){
        list<Account> colAccounts = [select id,Client_Code__c,First_Trade__c,Reactivation_Date__c,Client_FTT__c from Account where Client_Code__c in : MapAccount.keySet()];
        if(!colAccounts.isEmpty()){
            for(Account objAccount : colAccounts){
                if(objAccount.Client_Code__c != null){
                    MapAccountOpt.put(objAccount.Client_Code__c,objAccount);