0

I'm trying to write a dedupe trigger on Lead by which all newly created lead records which have email matching to already existing contacts will have the owner automatically assigned to a queue (Queue name - Data Quality). This is the code i've written and got compiled as well but when i'm creating a lead it's not getting assigned to the queue. Can anyone point me out what wrong i'm doing?

trigger dupeTrigger on Lead(before insert){

Set<String> leadEmails = new Set<String>();
Set<String> contactEmails = new Set<String>();

Group dataQualityGroup = [SELECT Id FROM Group WHERE DeveloperName = 'Data_Quality'];

for(Lead lead:trigger.new){
    leadEmails.add(lead.Email);
}

List<Contact> contactEmail = [SELECT Id,Email,FirstName,LastName,Account.Name FROM Contact WHERE Id IN :leadEmails];

for(Contact contact:contactEmail){
    contactEmails.add(contact.Email);
}

for(Lead lead:Trigger.New){

        if(contactEmails.contains(lead.Email)){
            lead.OwnerId = dataQualityGroup.Id;
        }

     }


 }
0

1 Answer 1

4

Your list is of the email address and your query is checking for and id in that list. Id's do not equal email addresses so no contacts are returned

It should be where email in :leadEmails

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .