1

I am trying to send out an email whenever a campaign member's status is updated. I have the email side of it set up and working and am able to call that class from a trigger. Since I do not want an email sent more then once to an individual member, I was thinking of creating a custom field and updating when an email was sent. However I do not know how to create a custom field and update it for a specific member. Psudo code would look something like this I believe

trigger MemberUpdate on CampaignMember (after insert, before update) {
for (CampaignMember cm : Trigger.new) {
  if (cm.Status == 'Communication Sent' && cm.WelcomeEmail=False) { 
  String SendId=='example@example.com'
  TriggeredSend.send();  //sends them an email
  boolean cm.welcomeEmail=true; //update custome field so email is send only once
}
}

I would also like to auto fill the campaign members email. Right now I pass the SendId string to TriggeredSend.send() but it is hardcoded. Thank you for any help.

1
  • I must ask, why are you using a trigger to send a very straightforward email? This can be done with a workflow, or the new process builder. – JodieM Apr 12 '15 at 7:38
1

To create the custom field go to setup->customize->campaign->campaign members->fields then scroll down to the "Campaign Member Custom Fields & Relationships" section and click new. As far as getting the email address, you could either query the contacts and leads or create a formula field and set it to the email address for the campaign member. Email appears to be available in formulas but not available in apex/soql.

enter image description here

4
  • I am trying to create a formula field and set it to the email address for the campaign member, however the formula editor does not have an option to select the member as the field type. It works for $user.Email but that is my email. How do I add a member option? Thank you. – Balazs Horanyi Aug 11 '14 at 20:41
  • Are you creating the formula field on the campaign member object? You should be able to just create a formula field there and select email directly from the campaign member object. – Jenny B Aug 11 '14 at 20:58
  • I added a screen shot, I'm guessing you might be on the Campaign object vs the Campaign Members object? – Jenny B Aug 11 '14 at 22:43
  • You are right, I needed to click on formula as the custom field, I had clicked on email. Thanks for the help – Balazs Horanyi Aug 11 '14 at 23:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.