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

Lead Conversion Error after Trigger Field Update
Hi...being new to triggers and APEX, I'm in need of some help on an error I received...
I currently have a trigger that automatically updates a Lead Status and Lead Custon Field (Stage_C) based on the completion of an Activity. Below is my code for the tigger...which, works perfect:
trigger changeLeadStatustask2 on Task (before insert, before update) {
List<Lead> LeadToUpdate = new List<Lead>();
for (Task tsk: Trigger.new){
if(tsk.Status=='Completed' && tsk.Subject=='Call to Qualify (Successful)'){
Lead ld = new Lead(Id=tsk.whoid);
ld.Status = 'Qualified';
ld.Stage__c = 'Qualified - Convert to QP';
LeadToUpdate.add(ld);
}
}
update LeadToUpdate;
}
However...when I attempt to convert this Lead into an Account, I get the below error/exception:
Error: System.DmlException: Update failed. First exception on row 0 with id 00TR000000EdoDYMAZ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, changeLeadStatustask2: execution of BeforeUpdate caused by: System.TypeException: Invalid id value for this SObject type: 003R000000ojtF5IAI Trigger.changeLeadStatustask2: line 5, column 1: [] (System Code)
Any help would be most appreciated!!! Thank you!!!
I currently have a trigger that automatically updates a Lead Status and Lead Custon Field (Stage_C) based on the completion of an Activity. Below is my code for the tigger...which, works perfect:
trigger changeLeadStatustask2 on Task (before insert, before update) {
List<Lead> LeadToUpdate = new List<Lead>();
for (Task tsk: Trigger.new){
if(tsk.Status=='Completed' && tsk.Subject=='Call to Qualify (Successful)'){
Lead ld = new Lead(Id=tsk.whoid);
ld.Status = 'Qualified';
ld.Stage__c = 'Qualified - Convert to QP';
LeadToUpdate.add(ld);
}
}
update LeadToUpdate;
}
However...when I attempt to convert this Lead into an Account, I get the below error/exception:
Error: System.DmlException: Update failed. First exception on row 0 with id 00TR000000EdoDYMAZ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, changeLeadStatustask2: execution of BeforeUpdate caused by: System.TypeException: Invalid id value for this SObject type: 003R000000ojtF5IAI Trigger.changeLeadStatustask2: line 5, column 1: [] (System Code)
Any help would be most appreciated!!! Thank you!!!
Try below code.
The change i have made is
1. Checking for Whoid is not equal to null , lead
2. Error handling try, catch
I have tested the below code is working. let m eknow if you have any questions.
All Answers
Try below code.
The change i have made is
1. Checking for Whoid is not equal to null , lead
2. Error handling try, catch
I have tested the below code is working. let m eknow if you have any questions.
Yes...worked perfectly!!! I have a few Triggers built for the same purpose but with different Statuses and Subjects...I modified them all with your code and was able to convert.
Are you able to easily explain what was preventing the conversion? I still need to read up on try, catch exceptions...just a lot to wrap my head around...lol!!!
Thanks again...I really appreciate your help!!! :)
E