You need to sign in to do that
Don't have an account?
Mario Conteddu 1
Checking and Unchecking contact checkbox based on campaign memeber
Hi Guys,
I need to write a trigger which will tick a checkbox in contact when the contact is member of a specific campaign. Furthermore, I need the same checkbox to be un-ticked when the contact has a date (end date) on a custom field which I created in the campaign member object.
I managed to get the checkbox ticked but I can't get it unticked when an end date is added. Can you please help me?
I need to write a trigger which will tick a checkbox in contact when the contact is member of a specific campaign. Furthermore, I need the same checkbox to be un-ticked when the contact has a date (end date) on a custom field which I created in the campaign member object.
I managed to get the checkbox ticked but I can't get it unticked when an end date is added. Can you please help me?
trigger updateContact on CampaignMember (before update){ List<id> contactIds=new List<Id>(); for(CampaignMember cm:trigger.new){ if(cm.ContactId != null){ System.debug('End Date of campaign membership is ' + cm.CM_End_Date__c); if(cm.CM_End_Date__c == null && cm.campaignId == '701b0000000FY9Z'){ 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; system.debug('Trustee status is now '+c.TestTrustee__c ); } }
Hi Mario,
Please update code as below and let me know if you face any issue:
Thanks for correcting my code.
I've tried id but nothing happens. When I add a contact to the campaignid 701b0000000FY9Z, the checkbox does not get ticked in the contact.
The debug shows the following, but it does not actually happen:
12:57:24.0 (129379795)|USER_DEBUG|[23]|DEBUG|Trustee status is now true
Hi Mario,
The trigger is on Campaign member. So trigger will run only when campaign member is updated.
This trigger will not fire on any event on Contact
When I add a contact to a campaign, a new campaing member for the same contact gets created. The campaign member creation should fire the trigger, right? I've also tried to updated the campain member, but it still dot not update the checkbox on the contact.
Hi Mario,
It will only work on updation of Campaign Member.