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;
}
}
}