You need to sign in to do that
Don't have an account?
Trigger to update contact level checkbox custom field based on campaign member status.
Hi,
I am new to salesforce trigger.NEED HELP!!!
I am trying to write a trigger to update contacts field with the response received tracked in campaign member object.
I have one field call Subcribered at contact level.When a contact is tagged for campaign then we are waiting for his reply after receiving the reply we update campaign member status.
So is there any way we can update the Subcribered checkbox as check once the campaign member status changed.
Suppose:
ABC has subscibed for the email then we change it status to Responed then salesforce should automatically update the his Subscribed checkbox.
Please help
Morning,
That line simply mention on which records the trigger is executed.
To know what is returned in your triggers, use System.debug statements.
There was indeed a slight error there => contactIds.add(cm.Id);
You can use the code bellow which i used in sandbox to test it and everything works well. I've left the system.debug statements on purpose so you understand how they work. But they should be removed afterwards.
Kr,
Fred
All Answers
This doesn't sound like you need a trigger. You could easily do this with a workflow from what you have described.
Thanks Scoobie!!!
Work flow for one object only where as this requires two object one is campaign member which is a object with campaign and another one is contact.
So first of all I have to check campaign member status on after insert and update where status is equals to responed and then update the field by referencing the contacts.
Hope this help to clear my view.
Thanks in advance!!!
Hi John,
Thanks a lot!
This code is not working.It is showing error :
"Error: Compile Error: Condition expression must be of type Boolean at line 5 column 7"
And according to me it is considering Campaign-Status which is checkbox(True or False) field.How to refer to "Campaign Member Status" field.
Thanks in advance!!!
Regards,
MktDev
Hi John,
I have updated the code "if(cm.Status='Subscribed'){" with "if(cm.Status!='Subscribed'){" and Code is saved and trigger created,
But When I update the member status trigger is not responding.Nothing is been done.
Regards,
Hi,
Use this instead
"!=" means not equal to and "==" equals to when in your if condition. The way you changed it, everytime a campaign member record is changed with a status different from 'Subscribed' it will trigger the update.
Kr
Hi Frederic,
Thanks a lot!
I have changed it and checked the log and found that the ID which is storing in the List is on Campaign Member ID which is not the contactID I tried to link Contact field of Members to the list but it not allowing me to save.How to find the contact ID for member ID they have chid relationship.
This is the output of the code:
5:10:29.54|CODE_UNIT_STARTED|[EXTERNAL]updateContact on CampaignMember trigger event BeforeUpdate for 00v90000000q1dN, 00v90000000q1dP, 00v90000000q1dQ
Bold ids are not contact ID its member ID.
Please help.
Thanks in advance
Morning,
That line simply mention on which records the trigger is executed.
To know what is returned in your triggers, use System.debug statements.
There was indeed a slight error there => contactIds.add(cm.Id);
You can use the code bellow which i used in sandbox to test it and everything works well. I've left the system.debug statements on purpose so you understand how they work. But they should be removed afterwards.
Kr,
Fred
Hi Frederic,
This is great!!! Much appreciated!
Regards,
Mktg
Oops :) Thanks for the fix.