0

Trying to figure something out. Working on this but its not working.

I have two fields in this one object under the account. One field is a contact name look up and the other is the email of the contact. The trigger is supposed to populate the email of the contact once the contact name is selected. Can you guys help me? thank you so much

trigger populateContactemail on Member_Assess__c (before insert , before update){

    Set<ID> setConIds = new Set<ID>();
    for(Member_Assess__c  obj : trigger.new){
        if(obj.Member_Name__c != null)
        setConIds.add(obj.Member_Name__c);
    }

     MAP<ID , Contact> mapCon = new MAP<ID , Contact>([Select Email__c from Contact where id in: setConIds]);
     for(Member_Assess__c  obj : trigger.new)
       {
        if(obj.Member_Name__c != null)
          {
            Contact  c = mapCon.get(obj.Member_Name__c);
            obj.email__c = c.email__c;
          }

       }
  • is address__c the email field? – cropredy Sep 13 '17 at 1:06
  • oops. fixed hehe... – user48169 Sep 13 '17 at 1:21
  • still not working though – user48169 Sep 13 '17 at 1:39
0

API Name for the email field on contact is email instead of email__c

trigger populateContactemail on Member_Assess__c (before insert , before update){
Set<ID> setConIds = new Set<ID>();
for(Member_Assess__c  obj : trigger.new){
    if(obj.Member_Name__c != null)
        setConIds.add(obj.Member_Name__c);
}
MAP<ID , Contact> mapCon = new MAP<ID , Contact>([Select Email__c from Contact where id in: setConIds]);
for(Member_Assess__c  obj : trigger.new)
{
    if(obj.Member_Name__c != null)
    {
        Contact  c = mapCon.get(obj.Member_Name__c);
        obj.email__c = c.email;
    }
}}

Let me know if this does not solve your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy