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
B&D DeveloperB&D Developer 

Help with Apex Code to Merge Leads

Hi All,

I need help creating an Apex Code to merge Leads created via Web to Lead once duplicate email address is detected. 
same thing with once a contact is created and if email address matches any of leads email address, Leads will be deleted.
Sound simple process but Salesforce don't have a declarative way to do it.

Thanks in advance.
AshwaniAshwani
Follow the following link https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_dml_examples_merge.htm

Ut has sample code to merge Account. You can use this code to merge Leads with a little modifications.
B&D DeveloperB&D Developer
Thanks,

is this going to be called automatically or should I create a process to call this Trigger?

 
AshwaniAshwani
You can write a trigger to merge leads. As well as you can manully merge lead using the code given in example. Both ways are possible.