You need to sign in to do that
Don't have an account?
Aaron Hill
Updating lead dupe catching recipe
Hey everyone,
I'm using a recipie from the Force.com cookbook to prevent duplicate records from saving. Here's the link: http://developer.force.com/cookbook/recipe/preventing-duplicate-records-from-saving
My question, how do I modify this code in another trigger so that it prevents lead/contact duplicates from being synched? Again this trigger should still be for leads being inserted but I want it to match against existing contact email rather than existing lead email. Thanks!
I'm using a recipie from the Force.com cookbook to prevent duplicate records from saving. Here's the link: http://developer.force.com/cookbook/recipe/preventing-duplicate-records-from-saving
trigger leadDuplicatePreventer on Lead (before insert, before update) { Map<String, Lead> leadMap = new Map<String, Lead>(); for (Lead lead : System.Trigger.new) { // Make sure we don't treat an email address that // isn't changing during an update as a duplicate. if ((lead.Email != null) && (System.Trigger.isInsert || (lead.Email != System.Trigger.oldMap.get(lead.Id).Email))) { // Make sure another new lead isn't also a duplicate if (leadMap.containsKey(lead.Email)) { lead.Email.addError('Another new lead has the ' + 'same email address.'); } else { leadMap.put(lead.Email, lead); } } } // Using a single database query, find all the leads in // the database that have the same email address as any // of the leads being inserted or updated. for (Lead lead : [SELECT Email FROM Lead WHERE Email IN :leadMap.KeySet()]) { Lead newLead = leadMap.get(lead.Email); newLead.Email.addError('A lead with this email ' + 'address already exists.'); } }
My question, how do I modify this code in another trigger so that it prevents lead/contact duplicates from being synched? Again this trigger should still be for leads being inserted but I want it to match against existing contact email rather than existing lead email. Thanks!
Test Class:- Update old Trigger with above Trigger!
All Answers
Works great in sandbox! I appreciate your help, if you don't mind, can you give me some pointers on fixing the test class too? Here is what I had for the other rule.
Thanks!
Any one please look at this issue
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000D817
Test Class:- Update old Trigger with above Trigger!
The trigger you provided above worked really well except for one small problem: when I try to convert a lead to a contact the trigger precents that conversion. Could we modify the code so that it allows us to convert contacts into leads?
Much obliged,
-Aaron