You need to sign in to do that
Don't have an account?

QueryException: Non-selective query against large object type (more than 100000 rows)
Hi,
I'm working on a update trigger, i.e, whenever Account.TID__c (Text field) is changed && Account.AccID__c (unique,ExternalId Text fields) is null, check all account which have Account.AccId__c != null and Account.TID__c !=Account.AccID__C, if it's true copy the Account.TID__c into the Account.AccID__C. I'm getting the following error
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): Class.UpdateAccIDController.updateAccID:
Any one can help me please ?.
Here is my code
trigger UpdateAccID on Account (after update) {
if ( Trigger.isUpdate ) {
UpdateAccIDController.updateAccID(trigger.oldMap, trigger.newMap);
}
}
public class UpdateAccIDController{
public static void updateAccID(Map<ID, Account> oldAccts, Map<ID, Account> newAccts){
Map<ID, Account> accounts = new Map<ID, Account>();
for(Account acc: newAccts.values()){
Account oldAcc = oldAccts.get(acct.Id);
if (acc.TID__c!= oldAcc.TID__c && acc.AccId__c == null){
for(Account accList:[select Id,AccID__c FROM Account WHERE AccID__c !=null]){
if( acc.TID__c != accList.AccID__c){
acc.AccID__c = acc.TID__c;
}
}
}
update acc;
}
}
}
Thank a lot .
Regards,
SK
The issue here is that your query filter contains 'Acc_Id__c != null', which means that every record has to be processed to check if that field is null. The recommendation is to use a value that represents null but isn't - 'N/A' or similar.
If you can't do that, can you do something with another custom field to store a 'Yes/No' value depending on whether the Acc_Id__c is populated and set that via trigger/workflow? That would allow you to query on the custom field not being equal to 'No' which should be indexable.