Using Mass Email Contacts with Campaign Merge Fields

Not possible you say? Well, yes, technically you are correct. However, I needed to use the standard mass email functionality in Salesforce, and to include both contact merge fields (First Name, Email) and campaign merge fields (Campaign name, Start date) in a URL in an email that would be sent every month from a new campaign.

The best solution I could come up with requires a bit of cut and paste, and a clever hack, but should be foolproof in that it doesnt require manually reassembling the URL in the email - just pasting a new link for each send.

My approach was as follows:

  1. create a formula field on the campaign object to pull the campaign merge fields into the URL
  2. On said formula field, after the campaign merge fields, include the contact merge fields that would get populated when the email was sent.

So the formula field, simplified to only include one Campaign field and one Contact field, looked like this:”&Name&“&tfa_36={!Contact.Id}

This was looking good, and worked perfectly except for one thing. When I saved the formula, Salesforce stripped out the opening {! and closing }, leaving you only Contact.Name, which does not do anything at all when you send the email. So you just have your campaign info, but none of your contact info.

I tried getting crafty by hiding the } using other functions. like IF(ISBLANK(Id),“”, “}” , but Salesforce easily picked that up and stripped out the beginning and ending brackets.

I was at the end of the road, but Sharif Shaalan on Answers had the bright idea to try using a custom formula field, with a value of “}”. So I created a formula field named Text_End_Bracket__c and gave it a default value of “}”, and added it to my Campaign formula field.

So now my formula field looks like:”&Name&“&tfa_36={!Contact.Id”&Text_End_Bracket__c

I then enclosed that in a hyperlink function, so when looking at a campaign, the user would just see “Copy This Link”

HYPERLINK(“”&Name&“&tfa_36={!Contact.Id”&Text_End_Bracket__c,“Copy This Link”)

Screenshot 2015-01-07 at 9.35.27 PM.png

The user can then copy that link, add it to an email template, and when the mass email is sent, the contact merge fields populate, and the campaign merge fields are already populated with the correct value.

Its not perfect, but it works, and the user can do it all w/out admins getting involved! Now if only Salesforce would let you send mass emails from Campaigns and include campaign merge fields.


Now read this

Custom User Controller Extension - to allow users to edit fields on user record

[update : captains log june 18 2020. #summer20 release. its a lot easier to use a flow that runs in system mode to do most anything that requires a without-sharing apex controller] As custom controllers can run in system mode,... Continue →