I'm getting an error message when I update my Contact name:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateCallsonContactNameChange: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows).
Considered an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when:
- The filter value includes null (for instance binding with a list that contains null)
- 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)
Second error:
Class.updatePhysiciansonContactNameChange.changeName: line 9, column 1 Trigger.UpdateCallsonContactNameChange: line 12, column 1: []"].
I'm giving my Trigger and class to analyze:
trigger UpdateCallsonContactNameChange on Contact (after update) {
if(updatePhysiciansNameonContactNameChange.RecursiveFlag)
{
updatePhysiciansNameonContactNameChange
.changeName(Trigger.NewMap.keyset(),Trigger.new,Trigger.oldMap);
}
}
In the class the
Physicianid
and Fellowid__c
are 2 lookup fields to the Contact
.
Below is my class:
global class updatePhysiciansonContactNameChange
{
public static Boolean RecursiveFlag = true;
public static void changeName(Set<Id> ids, List<Contact> conlist,
Map<Id, Contact> mapcontact)
{
List<Call__c> listcall = [select Id,Physicians__c,Physicianid__c,
Fellowid__c,Fellow__c from call__c
where Physicianid__c in :Ids or Fellowid__c In :ids];
List<Call__c> updateCalls = new List<Call__c>();
for (Contact con : conlist ) {
Contact oldcon= mapcontact.get(con.Id);
if(con.FirstName != oldcon.FirstName || con.LastName != oldcon.LastName) {
for (Call__c casrecord:listcall){
if(casrecord.Physicianid__c == con.id)
{
casrecord.Physicians__c = con.FirstName + ' ' + con.LastName;
}
else if(casrecord.Fellowid__c == con.id)
{
casrecord.Fellow__c = con.FirstName + ' ' + con.LastName;
}
updateCalls.add(casrecord);
}
}
}
RecursiveFlag = false;
update updateCalls;
}
}