Marketing Cloud Connect allows users to view a thumbnail of emails sent from Marketing Cloud in Sales and Services Cloud as part of its default setup, but long emails like newsletters or promotions can prove difficult to see. With some additional setup using Apex and Visualforce pages, we can allow Sales and Service Cloud users to view a full-resolution version of the email so they can remain fully informed about all the communications sent to a contact.
Sales and Service Cloud Tools
Apex and Visualforce Pages
Before beginning, it’s important to know what Apex and Visualforce pages are. Apex is a server-side programming language used by Salesforce to run custom code on the Salesforce platform. Apex allows organizations to extend Salesforce beyond what is possible with the built-in low code tools. In this case, you’ll use Apex to connect to Marketing Cloud's REST API to get the HTML of the email that was sent.
Visualforce pages are one of the tools Salesforce provides to build custom user interfaces and web pages on the Salesforce platform. Visualforce pages have the ability to display HTML and to run Apex. For this article, you’ll leverage these features to allow users to view the email sent to a contact.
What to Implement to Set Up Full Resolution Emails
Getting the Email Content from Marketing Cloud
The first step is connecting directly to Marketing Cloud from Sales or Service Cloud with Apex. To do so, you’ll use the Marketing Cloud REST API.
When setting up authentication to any system in Apex, it is a best practice to use Named Credentials. Authenticating with the Marketing Cloud API is no exception. Named Credentials allow you to securely store authentication information that your Apex code can reference. In addition, they also handle token refreshes automatically, so you don't need to account for expired tokens when building the Apex code.
Named credentials do not currently support the server-to-server authentication flow in Marketing Cloud, so you'll have to set up a custom OAuth process to use. Setting this up is outside the scope of this article, but if you have trouble implementing it, please reach out to us.
Once you have the custom OAuth process in place, Setting up Named Credentials is relatively simple. You'll set the URL to the Marketing Cloud REST API for your organization. Your identity type should be Named Principal with an authentication type of OAuth 2.0.
The callout itself is fairly straightforward since all we need to return is the HTML of the email we'd like to preview. You create the Apex class, make the callout, and parse out the results.
Setting Up the Visualforce Page
The Visualforce page setup looks very much like HTML but has additional tags you'll use to call the preview email Apex class and display it.
The end goal is to display the HTML email on the individual email results page layout, so you'll also need to make sure the Visualforce page is set up for in-line implementation. To make a Visualforce page in-line, you'll add in a few attributes to your apex:page tags. The standard controller lets the page know what object it's related to. The extension is the Apex class that is executed to display the HTML of the email you'd like to display.
Once the page is built, all that remains is to add it to the page layout you want the email to show on. You will also need to make sure that users who need to see the email are granted access to the Visualforce page and Apex classes.
Marketing Cloud Connect is a powerful tool for any organization using Marketing Cloud and Sales or Service Cloud. The default features bring basic visibility back to Sales and Service Cloud, but with some additional setup, you can extend that power to keep Sales and Service Cloud users informed about exactly what communication is being sent to their contacts. Viewing full resolution emails from Marketing Cloud is just one more way Marketing Cloud Connect brings more information to users. If you need help setting up full resolution emails in Sales and Service Cloud, contact us.
Need help with your Salesforce digital transformation? Contact us today to discuss Salesforce consulting, implementation, development, and support!
Download the Apex for Full Resolution Emails
Please complete the form below to download your FREE Salesforce file.