0

The Problem: We have some functionality that lives on both the lead object and the contact object. If someone, either a lead or a contact, requests a demo, the record gets time-stamped by our marketing integration and this triggers some other workflows & notifications.

If a lead gets stamped and then I convert the lead to a contact, those fields get mapped over. The issue is that it triggers the functionality on the contact all over again when really I've already followed up on that demo request. SO... all this to say that I need a way to determine if a contact is being converted from a lead and exempt that scenario from the logic.

I already have a solution that works which I'll post below, however it just feels like there must be a better way. I would love to hear more ideas on how others would solve this.

2 Answers 2

1

Use a global static variable, and you can detect this event (NOTE: "Enable Triggers and Validations on Lead Conversion" must be set in Lead Settings).

First, set up a static variable somewhere:

public class StaticVars {
    public static Boolean isConverting = false;
}

Then, set up a trigger on Lead:

trigger isConvertingFlag on Lead (before update) {
    StaticVars.isConverting = Trigger.new[0].IsConverted;
}

And then, modify your Contact trigger to determine what to do:

trigger updateContact on Contact (after insert, after update) {
    if(StaticVars.isConverting) {
        return;
    }
    // Do the rest of your logic here
}

Of course, feel free to follow your trigger handler's syntax, but the point is that you just need to flag the conversion during the Lead trigger phase, and you can detect it during the Contact, Account, and Opportunity trigger phases.

1
  • Awesome answer. Much cleaner and more versatile than creating field on the lead object. I was trying to blend in some of that logic in workflows which wouldn't be able to reference that class (far as I know), but I would much rebuild that stuff in the trigger and avoid the double update. May 18, 2016 at 16:33
0

1) Create a field on the lead object (IsLead__c) which will always be true

2) Create a field on the contact object which will default to false (IsConverting__c)

3) Map the IsLead__c field to the IsConverting__c field (this should be the only time that this field is ever true - in the transaction where the conversion is happening)

4) In an after insert/update trigger, check to see if the IsConverting__c field is == TRUE. If so, add it to a list that you will update after the transaction.

5) In a future method, process the contacts to set them all to IsConverting__c = FALSE and update

I don't like the fact that I have to update the records twice anytime I convert them, but maybe there isn't a better solution. Code snippet below in case anyone wants to use this same process.

EDIT: Removed the code. Don't do it this way. Check out the answer marked above instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .