+ Start a Discussion
tnstns 

Need to update a field in an existing Contact record when Lead from the web is received

When Lead is received with a checkbox marked (and will NOT be converted), can a Contact checkbox field be updated?
jkucerajkucera

How would you know which contact to update?  You need a link between the lead & contact, such as a custom lookup field on Lead, which points to Contact.

 

Then you'd need to somehow populate that field with the right contact.  

 

Once you have the link, you can create a custom formula field on Contact referencing your lead checkbox.

tnstns
Thank you. It would be the email address in the Lead, which would match that of an existing Contact record.
jkucerajkucera

Do you have someone that could code?  Assuming you have the custom fields in place, the Lead trigger would look something like this:

 

 

trigger getContactID on Lead (Before insert, before update){ List<lead> leadWithEmails=new List<Lead>(); Set<String> emails=new Set<String>(); integer Count=0; for (Lead l:trigger.new){ if (l.email!=null){ if (Trigger.isUpdate){ //more complex code to compare trigger.new to trigger.old if(l.email !=trigger.old[count].email){ leadWithEmails.add(l); if (emails.contains(l.email)==False){ emails.add(l.email); } } //if so, add to the list } else { leadWithEmails.add(l); if (emails.contains(l.email)==False){ emails.add(l.email); } } count++; } Map<String, ID> contactEmails=[Select email, ID FROM Contact WHERE Email IN: emails limit 1000];//not sure this will work - might need to first assign to a list & loop through the list to assign to a map For (Lead l2: leadWithEmails){ l2.contactID__c=contactEmails.get(l2.email); //Note ContactID__c is what I'm assuming your custom field that looks up to Contact is called } }

 I haven't tested itso likely there are a few syntax errors