+ Start a Discussion
Mario Conteddu 1Mario Conteddu 1 

Cross Object Field Update - Campaign Membership > Contact

Hi,

I've need to get a Contact checkbox field =TRU when the same contact is a campaign member of a specific campaign. Can you please help me? 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Mario, I hope it will be helpful.

BestRegards
RahulKumar
Mario Conteddu 1Mario Conteddu 1
Thanks Rahul. I actually need the other way around. I need to record in the contact record when a contact is part of a specific campaign, and has a specific campaign memebr status, too. 
Mario Conteddu 1Mario Conteddu 1
I've found some info in another form eventually and here is what I used:
trigger updateContact on CampaignMember (before update){
  List<id> contactIds=new List<Id>();
  for(CampaignMember cm:trigger.new){
    if(cm.ContactId != null){
      System.debug('Status is ' + cm.Status);
      if(cm.Status == 'Cancelled'){
        contactIds.add(cm.ContactId);
        System.debug('Id is ' + cm.ContactId);
      }  
    }
  }
  List<Contact> contacts=[SELECT Id,    TestTrustee__c FROM Contact WHERE Id IN : contactIds];
  for(Contact c:contacts){
      System.debug('Found contact ' + c);
    c.TestTrustee__c=True;
  }
  try{
    update contacts;
  System.debug('Contacts to update list size ' + contacts.size());
  }catch (DMLException e){
    system.debug('contact update failed: '+e);
  }
}