function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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) {
  List<String> LeadNames = new List<String>{};
  for(Lead myLead:{
   if((myLead.isconverted==false) && (myLead.status == 'Qualified')) {
  Database.LeadConvert lc = new database.LeadConvert();
          lc.convertedStatus = 'Qualified';
          Database.LeadConvertResult lcr = Database.convertLead(lc);

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!!!
This sounds more like the task trigger isn't working as expected.  If the lead status is not changed to 'Qualified' then your lead trigger will take no action.  Can you post the task trigger.
Thanks for your response Bob...below is the code:

trigger changeLeadStatustask2 on Task (before insert, before update) {
    List<Lead> LeadToUpdate = new List<Lead>();
        for (Task tsk:{
            if(tsk.Status=='Completed' && tsk.Subject=='Call to Qualify (Successful)' && 
           tsk.WhoId != null &&
                Lead ld = new Lead(Id=tsk.whoid);
                   ld.Status = 'Qualified';            
                   ld.Stage__c = 'Qualified - Convert to QP';
                update LeadToUpdate;
            catch(DMLException e){
                for(Task tsk:{
I can't see anything obviously wrong - have you tried adding debug statements and turning on debug logging?  What seems most likely is that you aren't adding any leads to the LeadToUpdate list, but I think you'll need to debug that to figure out exactly why.
I'm very new to this so I'm not well versed in writing debug statements yet...unfortunately.  I'll see if I can figure it out...

Thanks for your help Bob!!!