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

Trigger to auto-convert Lead when "Qualified" not working...and I know it's me! :)
Hi all,
Looking for some assistance here...I have a requirement to have a Lead automatically convert to an Account and Contact (no opportunity needed) when the Lead status is set to "Qualified". I also have an existing trigger on "Task" that when a particular picklist value is selected and the Task is marked "Completed" it will automatically change the Lead status to Qualified...that trigger works perfect in my Sandbox.
I've searched tons of articles on here about a trigger to auto-convert a Lead based on certain values and used the below code as suggested:
trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
if((myLead.isconverted==false) && (myLead.status == 'Qualified')) {
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.Id);
lc.convertedStatus = 'Qualified';
//Database.ConvertLead(lc,true);
lc.setDoNotCreateOpportunity(true);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}
}
}
Issue: When I complete a Task that fires the trigger to change the Lead status to Qualified, it says the Lead was converted, but when I go back to check, the Lead was NOT converted AND the Task does not show up in the activity history AND the Lead Status is unchanged (not showing as "Qualified") even though it should per the Task trigger...
I'm totally lost on this one...any help would be great...thanks in advance!!!
Looking for some assistance here...I have a requirement to have a Lead automatically convert to an Account and Contact (no opportunity needed) when the Lead status is set to "Qualified". I also have an existing trigger on "Task" that when a particular picklist value is selected and the Task is marked "Completed" it will automatically change the Lead status to Qualified...that trigger works perfect in my Sandbox.
I've searched tons of articles on here about a trigger to auto-convert a Lead based on certain values and used the below code as suggested:
trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
if((myLead.isconverted==false) && (myLead.status == 'Qualified')) {
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.Id);
lc.convertedStatus = 'Qualified';
//Database.ConvertLead(lc,true);
lc.setDoNotCreateOpportunity(true);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}
}
}
Issue: When I complete a Task that fires the trigger to change the Lead status to Qualified, it says the Lead was converted, but when I go back to check, the Lead was NOT converted AND the Task does not show up in the activity history AND the Lead Status is unchanged (not showing as "Qualified") even though it should per the Task trigger...
I'm totally lost on this one...any help would be great...thanks in advance!!!
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)' &&
tsk.WhoId != null &&
String.valueOf(tsk.WhoId).startsWith(Schema.SObjectType.Lead.getKeyPrefix())){
Lead ld = new Lead(Id=tsk.whoid);
ld.Status = 'Qualified';
ld.Stage__c = 'Qualified - Convert to QP';
LeadToUpdate.add(ld);
}
}
if(!LeadToUpdate.isEmpty()){
try{
update LeadToUpdate;
}
catch(DMLException e){
for(Task tsk: Trigger.new){
tsk.addError(e.getDmlMessage(0));
}
}
}
}
Thanks for your help Bob!!!