function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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);
  }
}