You need to sign in to do that
Don't have an account?
Allen2
Stop creation of duplicate contact on lead conversion
I've written the below piece of code and called in after update context on lead but doesn't work. Can anyone help me to correct the code.
I only want to write a trigger which will stop the creation of duplicate contact only when you're converting the lead.
public class LeadHandler { public static void dedupeContactOnLeadConversion(List<Lead> newList,map<id, Lead> oldLeadMap){ List<String> email = new List<String>(); List<String> firstName = new List<String>(); List<String> lastName = new List<String>(); for(Lead objLead: newList){ if(!String.ISBLANK(objLead.Email) && objLead.IsConverted == false){ email.add(objLead.Email); } if(!String.ISBLANK(objLead.FirstName) && objLead.IsConverted == false){ firstName.add(objLead.FirstName); } if(!String.ISBLANK(objLead.LastName) && objLead.IsConverted == false){ lastName.add(objLead.LastName); } } List<Contact> objContact = [Select Id, Email, FirstName, LastName from Contact where Email in: email OR FirstName in: firstName OR LastName in: lastName]; for(Contact newContact: objContact){ Database.LeadConvert lc = new Database.LeadConvert(); lc.setContactId(newContact.Id); Database.LeadConvertResult listLeadConvertResult = Database.convertLead(lc, false); } } }
I only want to write a trigger which will stop the creation of duplicate contact only when you're converting the lead.
Have you tried checking if it is working, you could test it in an anonymous window and see if it works?
Do let me know if it works and this is just a thought but as you are trying to stop the duplicate lead creation wouldn't it be better to do it on before insert or before update?
I hope this helps.
Regards,
Anutej
>>https://help.salesforce.com/articleView?id=duplicate_rules_standard_lead_rule.htm&type=5
>> https://help.salesforce.com/articleView?id=duplicate_prevention.htm&type=5
I hope this helps.
Link: https://salesforce.stackexchange.com/questions/14604/trigger-to-check-for-duplicate-contacts-on-lead-conversion
Above is the code for quick reference. Also, a note was mentioned below the implementation do check it according to your use case.