Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class checkDupes {
- public static void findDupes(){
- //create map to store lead info by email
- Map<String, Lead> leadMap = new Map<String, Lead>();
- //iterate through leads to populate map
- for(Lead ld : (List<Lead>)trigger.new){
- if(ld.email != null)
- leadMap.put(ld.email, ld);
- }
- //loop through all contacts where a matching email was found and
- //tie it to a particular lead and then error that lead out
- //skip process if leadMap is empty
- if(!leadMap.isEmpty()){
- for(Contact con: [SELECT id, email, firstName, lastName FROM Contact WHERE email IN :leadMap.keyset()]){
- if(leadMap.containsKey(con.email))
- leadMap.get(con.email).addError('A contact already exists with this email: '+con.firstName+' '+con.lastName+
- '<br/> <a href="https://kiterealty--casestudy.cs26.my.salesforce.com/'+
- con.id+'">Click here to view</a>', false);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement