You need to sign in to do that
Don't have an account?

Apex Trigger for Merge lead with same email or phone and make new lead master lead
Created this Apex class
please help me solve this problem
Thanks & Regards
SFDC Strange
public class DuplicateLeadMergeHandler { public static void MergeLead(List<Lead> newLead) { Set<String> emails = new Set<String>(); Set<String> phones = new Set<String>(); Map<String, Lead> masters = new Map<String, Lead>(); for(Lead ld : newLead) { emails.add(ld.Email); phones.add(ld.Phone); } emails.remove(null); phones.remove(null); for(Lead ld: [SELECT Id,Email,Phone FROM Lead WHERE (Email = :emails OR Phone = :phones) AND Id NOT IN :newLead AND IsConverted = false]) { If(ld.Email != Null) masters.put(ld.Email, ld); else If(ld.Phone != Null) masters.put(ld.Phone, ld); } for(Lead ld : newLead) { Lead master = new Lead(); If(masters != Null && masters.size() > 0 && masters.containskey(ld.Email)) { master = masters.get(ld.Email); } Else If(masters != Null && masters.size() > 0 && masters.containskey(ld.Phone)) { master = masters.get(ld.Phone); } If(master != null) { merge master ld; } } } }but its showing an error
Thanks & Regards
SFDC Strange
First you need to check validation rules, so open lead object and goto validation rules and check for this error message.
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
I have tried the same code. its working for me.
Thanks!!
We currently don't have any validation rules present in the lead Object right now.
Please check my code and give some suggestions as to it's my first time using the Merge function,
Please help and advise.
Thanks
SFDC Strange
Is the code merging leads with the same email or phone and making a new lead master lead?
please check and reply
Thanks
SFDC Strange
Please use below code:-
for more rfference use this link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_merge.htm
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
This code is also not working still showing the same error and I'm not able to understand this error.
Please help me.
Thanks
Himanshu