You need to sign in to do that
Don't have an account?
Ralf Wittenberger
Indexed Filter on Trigger
Hi,
i have a Trigger where I am searching for a value in a case to lookup on accounts to fill in the account id to the case.
The Trigger works well so far in the sandbox, but when i want to validate to get in in production deployed, it returns the following issue:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountOnCases: execution of BeforeInsert 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.AccountOnCases: line 7, column 1
Here is the trigger:
trigger AccountOnCases on Case (before insert) {
List<String> Account = new List<String>();
for (Case a:Trigger.new)
{
Account.add(a.Customer_Number_Lookup_C__c);
}
List <Account> AccountList = [Select ID from Account where Customer_Number__c in :Account];
if (AccountList.size() > 0) {
for (Integer i = 0; i < Trigger.new.size(); i++)
if (Trigger.new[i].Customer_Number_C__c != null)
{
Trigger.new[i].AccountID = AccountList[i].ID;
}
else
{
Trigger.new[i].AccountID = null;
}
}
}
Do you have an idea, how to solve this?
Thanks in advance
Ralf
i have a Trigger where I am searching for a value in a case to lookup on accounts to fill in the account id to the case.
The Trigger works well so far in the sandbox, but when i want to validate to get in in production deployed, it returns the following issue:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountOnCases: execution of BeforeInsert 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.AccountOnCases: line 7, column 1
Here is the trigger:
trigger AccountOnCases on Case (before insert) {
List<String> Account = new List<String>();
for (Case a:Trigger.new)
{
Account.add(a.Customer_Number_Lookup_C__c);
}
List <Account> AccountList = [Select ID from Account where Customer_Number__c in :Account];
if (AccountList.size() > 0) {
for (Integer i = 0; i < Trigger.new.size(); i++)
if (Trigger.new[i].Customer_Number_C__c != null)
{
Trigger.new[i].AccountID = AccountList[i].ID;
}
else
{
Trigger.new[i].AccountID = null;
}
}
}
Do you have an idea, how to solve this?
Thanks in advance
Ralf
Such type of errors occurs when we have NULL value in filter criteria of SOQL. Please make sure you don't have NULL value in Account list.
Perform NULL check before adding the values to list:
for (Case a:Trigger.new)
{
if(a.Customer_Number_Lookup_C__c!=null)
Account.add(a.Customer_Number_Lookup_C__c);
}
All Answers
Such type of errors occurs when we have NULL value in filter criteria of SOQL. Please make sure you don't have NULL value in Account list.
Perform NULL check before adding the values to list:
for (Case a:Trigger.new)
{
if(a.Customer_Number_Lookup_C__c!=null)
Account.add(a.Customer_Number_Lookup_C__c);
}