Activity Forums Salesforce® Discussions How can I determine whether a lead conversion was a merge to an existing contact or a new contact?

  • How can I determine whether a lead conversion was a merge to an existing contact or a new contact?

    Posted by Deepak on October 11, 2019 at 12:33 pm

    How can I determine whether a lead conversion was a merge to an existing contact or a new contact in salesforce?

    Laveena replied 5 years ago 2 Members · 1 Reply
  • 1 Reply
  • Laveena

    Member
    October 11, 2019 at 1:16 pm

    Hi Deepak,

    if (lead.IsConverted && !trigger.oldmap.get(lead.id).IsConverted) {

    // process all merges that had to do with Contacts
    if (trigger.newmap.get(lead.id).ConvertedContactId <> null) {

    if(trigger.newmap.get(lead.id).Status == '-Merge Contact') {
    // Existing Contact
    // Delete all existing Status Trackers for lead
    leadIdsToDeleteStatusTracker.add(lead.id);
    }
    else {
    // New Contact
    // Get all existing Status Trackers for lead and migrate to new Contact id
    leadIdContactIdToUpdateStatusTracker.put(
    lead.id,
    trigger.newmap.get(lead.id).ConvertedContactId
    );
    }
    }

    }

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos