I have a trigger implemented that will change the lead status to converted if a contact is created with the same email address. I'm trying to create a new trigger that changes a lead status to converted if the lead is inserted and a contact already exists with the same email address as that lead. I believe the following to be correct, except for this section:
for(Lead singleLead:leads){
singleLead.Status = 'Converted';
}
I get this - Error: Compile Error: Loop variable must be of type SOBJECT:Contact at line 16 column 14. After trying almost literally every combination of lead and contact objects there I can't figure out how to make this work. I can eliminate one error message, only to create another until I'm right back where I started.
Here is the full code:
trigger ConvertLead on Lead (after insert) {
List<String> leadEmails = new List<String>();
for(Lead lead:Trigger.new){
leadEmails.add(lead.Email);
}
List<Contact> leads = [
SELECT
Id, Email
FROM
Contact
WHERE
Email IN :leadEmails
];
for(Lead singleLead:leads){
singleLead.Status = 'Converted';
}
update leads;
}
Thank you for your help!