0

I attempted to use the Lead.IsConverted flag to update a checkbox on a related record in the after update context however it does not appear that converting the lead activates the trigger code:

    if (trigger.isUpdate){
        Date oldFollowUpDate = trigger.oldMap.get(lead.id).Follow_Up_Date__c;
        Date newFollowUpDate = trigger.newMap.get(lead.id).Follow_Up_Date__c;

        if (oldFollowUpDate != newFollowUpDate || lead.IsConverted){
            comp.Id = existingCompanies.get(lead.rWeb_Domain__c).Id;
            comp.Follow_Up_Date_Changed__c = true;
        }
    }

        //Add companies to upsert
        companyUpsert.add(comp);
    }

If I remove the IsConverted condition the trigger will properly run when the field Follow_Up_Date__c is changed. That act is what I want to replicate when the lead is converted but adding the condition does not appear to work.

Searching google for "Lead trigger activation" is really only giving me advice on creating triggers that automatically convert leads for me which is not what I am looking for.

Is it possible converting a lead does not count as an update on the lead?

  • Triggers do fire during conversion. I suspect your logic flaw lies elsewhere in your code. – sfdcfox Aug 26 '17 at 2:02
  • I see that you're grabbing the newFollowUpDate value from Trigger.newMap instead of reading it directly from the lead variable, but then reading the IsConverted flag directly from that same variable. What actually defines the variable called "lead" here? If you drop System.debug statements to check the IsConverted flag in both your lead variable and in your Trigger.newMap, are they as you would expect them? – Ginour Aug 28 '17 at 6:34
1

See the Apex Developer Guide:

Operations That Don't Invoke Triggers

The before triggers associated with the following operations are fired during lead conversion only if validation and triggers for lead conversion are enabled in the organization:

  • insert of accounts, contacts, and opportunities
  • update of accounts and contacts

Navigate to Setup > Customize > Leads > Lead Settings and make sure the Require Validation for Converted Leads setting is true.

Require Validation for Converted Leads

  • That snippet mentions the before context; will my code in the after context still run? – JaredT Aug 25 '17 at 18:58
  • @JaredT It should affect all triggers. The help text certainly implies as much. – Adrian Larson Aug 25 '17 at 19:00
  • Confirmed the 'Require Validation` box was checked and the errant behavior persisted (apparently the box was already checked) – JaredT Aug 25 '17 at 19:09
0

So after much trial and error, I found the solution which seems obvious in retrospect.

I simply added an IF() block to the before update context that sets Follow_Up_Date__c to null if IsConverted is true. This in turns uses my existing trigger logic to flag Follow_Up_Date_Changed__c.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.