You need to sign in to do that
Don't have an account?
mike.rametta.ax1705
Trigger To Tie a Lead to a Contact based on Email
I have a trigger I want to update a related field in the Lead Object To Store the Related Contact based on an email match.
trigger LeadTrigger on Lead (before insert, before update, after insert, after update) { if(Trigger.isBefore) { List<String> leadEmails = new List<String>(); for(Lead lead:Trigger.new) { leadEmails.add(lead.Email); } List<Contact> contacts = [SELECT id, Unique_Email__c FROM Contact WHERE Email IN :leadEmails ]; Set<String> contactEmails = new Set<String>(); Set<String> contactID = new Set<String>(); for(Contact contact:contacts) { contactEmails.add(contact.Unique_Email__c); contactEmails.add(contact.id); } for(Lead lead:Trigger.new) { if(contactEmails.contains(lead.Email)){ // This is where i am having the problem Once i have the set lead.Contact__c = contactID.id; } } } else { //gonna do something else here } }
So the issue is once I have the set I cant seem to get it to assing the contact to the Lookup field in the Lead object I get an error saying the initial term of the field expression must be an Sobject Set <String>
Not sure i udnerstand what i am doing wrong any help would be appreciated
You need to replace your sets with a map:
All Answers
You need to replace your sets with a map:
Thanks that was it