You need to sign in to do that
Don't have an account?
Sahil Yadav
Wants to update an existing lead record based on new lead record
Hello,
I had a scenario where When user creates a Lead we need to first check that Is this an Existing Lead or not.Based on the data on New Lead record page.
If that data matches with the existing record then just update the record based on the field values that are provided and DO NOT CREATE THE NEW LEAD.
If that data does not matches with the existing records then just CREATE NEW LEAD
SO from the code its updating the email field values for an existing recoord but at the same time its creating a new record as well and i needed to restrict the creation of a new record .
Any Suggestion would be helpfull!!!
I had a scenario where When user creates a Lead we need to first check that Is this an Existing Lead or not.Based on the data on New Lead record page.
If that data matches with the existing record then just update the record based on the field values that are provided and DO NOT CREATE THE NEW LEAD.
If that data does not matches with the existing records then just CREATE NEW LEAD
trigger LeadTrigg on Lead (before insert){ switch on Trigger.operationType { when Before_Insert{ Set<String> leadFname = new Set<String>(); for(Lead l : trigger.new){ leadFname.add(l.firstname); } if(leadFname.size()>0 && leadFname != null){ List<Lead> leadList = [Select id, firstname,email from Lead where firstname IN:leadFname]; Map<String ,Lead> mapNameWiseAccount = new Map<String,Lead>(); For(Lead le: leadList) { mapNameWiseAccount.put(le.firstname ,le); } For(Lead le : trigger.new) { if(mapNameWiseAccount.containsKey(le.firstname)) { if(le.email != null){ leadList[0].email = le.email; le.Id = leadList[0].id ; update leadList; } } } } } } }
SO from the code its updating the email field values for an existing recoord but at the same time its creating a new record as well and i needed to restrict the creation of a new record .
Any Suggestion would be helpfull!!!
You do this by using merge functionality.
Refer the below link have solution for similar kind of ask.
https://salesforce.stackexchange.com/questions/293825/create-a-trigger-to-merge-leads-if-the-email-already-exists-on-a-lead
If this helps, please mark it as best answer.
Thanks!!
walgreenslistens (https://www.walgreenslistens.win/)