I am going to write a trigger on the Associated Market object. This trigger will use the email address on the Associated Market record and look for a matching email address on the contact record. If a matching email address is found, then the Associated Market record Contact field should be populated with the contact found.
Below is my trigger:
trigger EmailMatchwithContactEmail on Associated_Market__c (before insert) {
Set<Id> conEmailId = new Set<Id>();
for(Associated_Market__c assMarket : trigger.New) {
conEmailId.add(assMarket.Email__c);
}
List<contact> conList = [select Id, Email, Name from contact where Email in : conEmailId];
Map<Id, contact> EmailMatchToContactMap = new Map<Id, contact>();
for(Associated_Market__c assMarket : conList){
EmailMatchToContactMap.put(assMarket.Email__c, assMarket);
}
for(Contact c : conList) {
if(c.Email != null){
c.Name = EmailMatchToContactMap.get(c.Email).id;
}
}
}