You need to sign in to do that
Don't have an account?
Bulking query in trigger error - CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
I am getting the following errors
Trigger.FindOrCreateContact_Trigger: line 7, column 13
caseAssignmentUpdateTest.caseAssignmentTest System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FindOrCreateContact_Trigger: execution of AfterInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.FindOrCreateContact_Trigger: line 7, column 13
ContractClass.testCaseCreation System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FindOrCreateContact_Trigger: execution of AfterInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
My trigger Code:
trigger FindOrCreateContact_Trigger on Case (after insert) {
Map<ID,Contact> contactMap;
Map<Id, String> csMap;
for (Case newCase:System.Trigger.new)
{
if(newCase.contactid == null){
csMap.put(newCase.Id, newCase.Suppliedemail);
//Map<ID, Contact> m = new Map<ID, Contact>([Select id, c.email from Contact c WHERE email IN emails]);
}
}
contactMap = new Map<ID, Contact>([select id, email from contact WHERE email IN :csMap.values()LIMIT 1]);
for(Case updateCase: Trigger.new){
if(csMap.containsKey(updateCase.id)){
for(Contact c: contactMap.values()){
if (updateCase.SuppliedEmail == c.Email) {
updateCase.ContactID = c.ID;
}
}
}
}
}
Map<ID,Contact> contactMap; Map<Id, String> csMap;
should be
Map<ID,Contact> contactMap = new Map<ID,Contact>(); Map<Id, String> csMap = new Map<ID,String>();
Jeremy Kraybill
Austin, TX
All Answers
Map<ID,Contact> contactMap; Map<Id, String> csMap;
should be
Map<ID,Contact> contactMap = new Map<ID,Contact>(); Map<Id, String> csMap = new Map<ID,String>();
Jeremy Kraybill
Austin, TX
Thank you for the quick response.
I am getting the following error now
caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FindOrCreateContact_Trigger: execution of AfterInsert
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.FindOrCreateContact_Trigger: line 11, column 5
I updated the query to check for the emai !=NULL
[select id, email from contact WHERE email != NULL AND email IN :csMap.values()LIMIT 1]);
Is this because contact.email is not indexed?
Thanks
Uma
This topic is covered in the forums elsewhere, this thread has a decent write-up of your options.
Jeremy Kraybill
Austin, TX
Really where?