You need to sign in to do that
Don't have an account?
Bayarea 101
Why Apex trigger is firing on lead
I have this apex trigger for Task and lead.
trigger UpdateCallCenterLead on Task (after insert, after update) {
List<Task> TId = New List<Task>();
Set<Id> LeadId = New Set<Id>();
List<Lead> UpdatedLead = New List<Lead>();
integer i = 0;
for(task t:Trigger.New){
if(t.call_disposition__c != null && t.WhoId != null){
tId.add(t);
LeadId.add(t.WhoId);}
}
Map<ID, Lead> LeadMap = new Map<Id, Lead>([SELECT Id, email, HasOptedOutOfEmail, DoNotCall, Status, Name, Company FROM Lead WHERE Id IN:LeadId]);
Lead l;
for (Task tas:tId){
l = LeadMap.get(tas.WhoId);
if( tas.action_reasons__c == 'Future Need (Potential)'){
l.status = 'Contacted - Future Potential';
UpdatedLead.add(l);}
if( tas.action_reasons__c == 'Interested – Transferred to BBC'){
l.status = 'Qualified';
UpdatedLead.add(l);}
if( tas.non_action_reason__c == 'Doing business with existing bank – no need to switch'){
l.status = 'Contacted - No Interest';
UpdatedLead.add(l);}
if( tas.non_action_reason__c == 'Other'){
l.status = 'Unqualified';
UpdatedLead.add(l);}
if( tas.call_disposition__c == 'DO NOT contact again'){
l.status = 'Unqualified';
l.HasOptedOutOfEmail = TRUE;
l.DoNotCall = TRUE;
UpdatedLead.add(l);}
if( tas.call_disposition__c == 'Wrong Contact Info'){
l.status = 'Unqualified';
UpdatedLead.add(l);}
if( tas.call_disposition__c == 'Second Attempt- Exhausted'){
l.status = 'Exhausted';
UpdatedLead.add(l);}
if( l.status == 'Contacted - Future Potential' && (tas.call_disposition__c == 'Left Message'
||tas.call_disposition__c == 'No Answer')){
l.status = 'Contacted - Future Potential';
UpdatedLead.add(l);}
if( l.status != 'Contacted - Future Potential' && (tas.call_disposition__c == 'Left Message'
||tas.call_disposition__c == 'No Answer')){
l.status = 'Contact Attempted';
UpdatedLead.add(l);}
If(UpdatedLead.size()>0){
update UpdatedLead;}
}
}
if i use ti with jut "after Insert" it works fine but lead status i not update when task is edit.Issue is when i click on lead convert button it generates an error
System.DmlException: Update failed. First exception on row 0 with id 00TL000000C6BChMAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateCallCenterLead: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.UpdateCallCenterLead: line 36, column 1: [] (System Code)
any suggestions what am i doing wrong.
trigger UpdateCallCenterLead on Task (after insert, after update) {
List<Task> TId = New List<Task>();
Set<Id> LeadId = New Set<Id>();
List<Lead> UpdatedLead = New List<Lead>();
integer i = 0;
for(task t:Trigger.New){
if(t.call_disposition__c != null && t.WhoId != null){
tId.add(t);
LeadId.add(t.WhoId);}
}
Map<ID, Lead> LeadMap = new Map<Id, Lead>([SELECT Id, email, HasOptedOutOfEmail, DoNotCall, Status, Name, Company FROM Lead WHERE Id IN:LeadId]);
Lead l;
for (Task tas:tId){
l = LeadMap.get(tas.WhoId);
if( tas.action_reasons__c == 'Future Need (Potential)'){
l.status = 'Contacted - Future Potential';
UpdatedLead.add(l);}
if( tas.action_reasons__c == 'Interested – Transferred to BBC'){
l.status = 'Qualified';
UpdatedLead.add(l);}
if( tas.non_action_reason__c == 'Doing business with existing bank – no need to switch'){
l.status = 'Contacted - No Interest';
UpdatedLead.add(l);}
if( tas.non_action_reason__c == 'Other'){
l.status = 'Unqualified';
UpdatedLead.add(l);}
if( tas.call_disposition__c == 'DO NOT contact again'){
l.status = 'Unqualified';
l.HasOptedOutOfEmail = TRUE;
l.DoNotCall = TRUE;
UpdatedLead.add(l);}
if( tas.call_disposition__c == 'Wrong Contact Info'){
l.status = 'Unqualified';
UpdatedLead.add(l);}
if( tas.call_disposition__c == 'Second Attempt- Exhausted'){
l.status = 'Exhausted';
UpdatedLead.add(l);}
if( l.status == 'Contacted - Future Potential' && (tas.call_disposition__c == 'Left Message'
||tas.call_disposition__c == 'No Answer')){
l.status = 'Contacted - Future Potential';
UpdatedLead.add(l);}
if( l.status != 'Contacted - Future Potential' && (tas.call_disposition__c == 'Left Message'
||tas.call_disposition__c == 'No Answer')){
l.status = 'Contact Attempted';
UpdatedLead.add(l);}
If(UpdatedLead.size()>0){
update UpdatedLead;}
}
}
if i use ti with jut "after Insert" it works fine but lead status i not update when task is edit.Issue is when i click on lead convert button it generates an error
System.DmlException: Update failed. First exception on row 0 with id 00TL000000C6BChMAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateCallCenterLead: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.UpdateCallCenterLead: line 36, column 1: [] (System Code)
any suggestions what am i doing wrong.
First things first, if you use the <> button on the toolbar, you'll be able to share code thats nicely formatted with line numbers.
Line 36, is:
which i suspect is null, causing your issue. Actualy, to be specific, I suspect L is null.
Error: Compile Error: Method does not exist or incorrect signature: [Id].startsWith(String) at line 17 column 64