You need to sign in to do that
Don't have an account?
Natasha Ali 3
Trigger to stop duplicate records into SF if email already exists on a person account
Hi,
I have an existing trigger which converts leads into peron accounts if the company name is blank.
I need to also write a trigger that stops records from coming into Salesforce if that email already exisits in a contact or an account (we use person accounts).
The issue is how do I get ti working with the existing trigger (I need it to run before the trigger that converts it into a person account is run). Is there a way to combine the two or add the functionality to create the record only if the email address doesn't already exist as a contact in the org.
Below is the autoconvert trigger:
Many Thanks,
Natasha
I have an existing trigger which converts leads into peron accounts if the company name is blank.
I need to also write a trigger that stops records from coming into Salesforce if that email already exisits in a contact or an account (we use person accounts).
The issue is how do I get ti working with the existing trigger (I need it to run before the trigger that converts it into a person account is run). Is there a way to combine the two or add the functionality to create the record only if the email address doesn't already exist as a contact in the org.
Below is the autoconvert trigger:
Trigger AutoConvert on Lead (after insert) { LeadStatus convertStatus = [ select MasterLabel from LeadStatus where IsConverted = true limit 1 ]; List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>(); for (Lead lead: Trigger.new) { if (!lead.isConverted && lead.Company == null) { Database.LeadConvert lc = new Database.LeadConvert(); String oppName = lead.Name; lc.setLeadId(lead.Id); lc.setDoNotCreateOpportunity(true); lc.setConvertedStatus(convertStatus.MasterLabel); leadConverts.add(lc); } } if (!leadConverts.isEmpty()) { List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts); } }Any help is MUCH appreciated!!
Many Thanks,
Natasha
I see that there are coupl of ways to prevent records from creation.
1. Use the native Duplicate management
2. Setup the custom validation using apex which would throw an error preventing record creation.
https://developer.salesforce.com/forums/?id=906F0000000BVQLIA4
Let me know if this helps.
Cheers!
So we already have rules but they are not working properly and are unreliable (already spoke to SF about it). I need to add it into my trigger - I posted this on the stackexchaneg community too and got the following response:
Is there anything else I would need to add? A separate handler class for the logic? How would I accomplish this?
Any help is much appreciated :)
Many Thanks,
Natasha