function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
alex jainalex jain 

Hello all! I have one requirement please help me.

if lead email and contact email are matched then assign that lead to matched contact else assign that lead to primary contact using apex?
Naren9Naren9
Hi Alex,
Your requirement is not clear. What do you mean by assign the lead to matched Contact.Please elaborate the requirement.
To give an idea on Trigger, below trigger will execute when a New Lead in inserted and it will check for the matched Contacts with the Lead Email and Update the Lead Description with the Contact ID.You can modify this trigger according to your requirement.

trigger DeDupeLead on Lead (before insert) 
{      
    for (Lead myLead: Trigger.new)
    {
        if(myLead.Email !=null)
        {
                //Search for Matach Contacts
                List <Contact> matchingContacts = [Select Id,FirstName,Lastname,Account.Name from Contact where Email=:myLead.Email];
                system.debug(matchingContacts.size() + 'Contact(s) found.');
                        //If matches are found
                 if(!matchingContacts.isEmpty())
                    {
                        
                    //Add the Dupe Contact IDs to Lead Description.
                        String dupeContactMessage = 'Duplicate Contact(s) found:\n';
                        for (Contact c : matchingContacts)
                        {
                            dupeContactMessage += C.FirstName+''+C.LastName+''+C.Account.Name+C.Id;
                        }
                        if(myLead.Description !=null)
                        {
                      dupeContactMessage += '\n' +  myLead.Description;    
                        }
                        myLead.Description=dupeContactMessage;
                        
                    }
        }
    }

}


Thanks,
Narendar





 
alex jainalex jain
Hello Narendar,

          Thanks for your reply. My requirement is :


When looking up the Contact/Member from the Contact-object.
First Check for Contacts that have that email address and MEMBERSHIP ACTIVE/Current.

If more than one match found then check the Member First Name and Last Name.
    If no Match found, then and still the email address is correct/active then assign to Primary Household.
    If match found, then attach the Lead to the contact# that matched.


Thanks,
Alex