This week Salesforce Labs has released a Lightning Component which, no doubt, will make the life easier for anyone working with Journey Builder and Marketing Cloud Connect.
If you have multiple Journeys set up in your account with different Salesforce Entry Events, you probably know the pain of finding out which Sales/Service Cloud Contacts and Leads are currently in the Journeys. And if you need to eject a Contact/Lead from a Journey immediately? You either end up doing it in POSTMAN or developing your own app on CloudPages just for that purpose.
Marketing Cloud Journeys for Salesforce is a Lightning Component which can be added to the Contact, Lead, Case or Account page and it will display the list of Salesforce Marketing Cloud Journeys that the subscriber is currently in, along with a stop button to allow instant removal of said subscriber from the Journey.
It’s available for free from AppExchange: Marketing Cloud Journeys for Salesforce, and you need to have Admin permissions in both Sales/Service Cloud and in Marketing Cloud to be able to install it.
Here’s the high level overview of the installation process (detailed guide can be found here):
Create a Package in Marketing Cloud with the component: API integration > Web App
In your Salesforce org, configure Auth. Provider with type Open ID Connect and paste all the details of the Marketing Cloud API package created in the previous step
In your Salesforce org, configure the Named Credential and test the Authentication Flow on save
Add the Lightning Component to Record Pages by opening any Contact, Lead, Case or Account and clicking on the Setup menu at the top right and choosing Edit Page
One important prerequisite, which is not clearly described in the installation guide, is the requirement to have a “Contact Key” field on the object for which you want to display the component. You do not need to create that field separately – it’s enough that you just point to the field containing the ID used as Subscriber Key in Marketing Cloud, for example Lead Id or Contact Id:
Now the updated page will display the component and list all the Journey names and their current active version, in which the subscriber is present:
It will also give you the option to eject the subscriber from a selected Journey, or from all active Journeys:
Upon clicking on the Stop/Stop All Journeys option, you will be prompted to confirm:
Salesforce Labs is closing a major gap in the cross-cloud functionality with this small, yet powerful and much needed addition. The component has proven to work correctly in the few simple tests I gave it and I would recommend anyone using Salesforce Marketing Cloud’s Journey Builder with Sales/Service data to also give it a go.
In this tutorial, you will learn how to create a simple, yet fully customizable profile and subscription centre integrated with Sales and Service Cloud. Bear in mind, that the script utilizes a couple of standard and custom Sales/Service Cloud fields, which you will need to adjust based on your Salesforce CRM setup – the full list can be found here.
The profile center is a webpage where subscribers can enter and maintain the personal information that you keep about them. When you import a list, you can import attribute values for your subscribers that appear when a subscriber visits the profile center. The subscriber can update their information on this page and provide additional information.
A subscription center is a web page where a subscriber can control the messages they receive from your organization. The lists (including publication lists) you identify as public in the application are available for a subscriber to opt in to on the subscription center.
If you’re using Marketing Cloud Connect to integrate with Sales/Service Cloud, you can use the standard Profile Center based on the Marketing Cloud attributes that are mapped to fields in Sales or Service Cloud. Marketing Cloud Connect documentation states, that changes made in the Profile Center update Salesforce contact and lead data – unfortunately I haven’t been able to confirm this with my tests.
Another limitation which is very hard to overcome is the look and feel of the standard Profile and Subscription Center. If you enable Marketing Cloud BrandBuilder, you will be able to customize the color scheme of your Profile and Subscription Center based on the colors of the logo you upload – but you won’t be able to change the layout or the fonts used.
Sooner or later, most Marketing Cloud users switch to custom Profile and Subscription Centers, as the standard one is not enough when it comes to more complex use cases.
In the form, you can include any fields from any of the relevant Sales/Service Cloud objects, but to make it more simple as we go, for now, we will use three standard fields from the Contact object: FirstName, LastName and Email. Additionally, I have added three read-only checkboxes to the Contact object for subscription management: Newsletter, Offers and Events. [Why are they read-only? In this tutorial, you will learn how to allow subscribers to make changes to their preferences and sync those changes back to Salesforce. The process of managing the subscriptions by a Salesforce user and syncing the changes back to Marketing Cloud is a separate procedure and won’t be addressed in this article.] I also made sure that the Email Opt Out flag is visible on a Contact page layout in Sales Cloud:
Here is a reference of all the fields from the Contact object, which we will use in our script:
API Field Name
Email Opt Out
Let’s now create a simple HTML form which contains all of the above fields:
Since we want the form to be pre-populated with subscriber data from Sales/Service Cloud, we need to add the RetrieveSalesforceObjects function to pull the data, and display the retrieved data as field values:
You will also notice in the above script, that we have added a form action. The RequestParameter('PAGEURL') function reloads the page when the form is submitted, posting the form parameters back to the same page. You can, of course, post the form data to another page and process it there, but for the purpose of this tutorial, let’s keep everything on one page so that it’s easier to copy and paste.
After the form is submitted and posted, the data can be retrieved by using the RequestParameter AMPscript function. We will then update the data in Sales/Service Cloud using the UpdateSingleSalesforceObject function. Let’s add them now:
Congratulations – you just built the first, simple version of your profile and subscription center!
Now let’s analyze the above script. The first thing that you will notice is that all the AMPscript is placed at the beginning of the document, above the form – that’s because the form data first has to be posted before it can be processed, and upon posting the data, the page reloads and starts resolving the script from top-down. If you need more clarification on this concept, click here.
If the form has been submitted, we will update the Sales/Service Cloud contact with the new data that was posted upon form submission. The form data is retrieved using the RequestParameter function, which is used in the @updateRecord variable inside the UpdateSingleSalesforceObject function.
You will also notice, that for each of the checkboxes, I have added the following in-line IF function: Iif(RequestParameter("newsletter") == "on", "true", "false"). That is because the checkbox passed from the HTML form will have a value of either on or off, while to pass it to Sales/Service Cloud, we need to convert it to a boolean value of true or false.
Unsubscribe From All option
To make the functionality of our custom subscription and profile center similar to the standard one, we can add the Unsubscribe From All and Resubscribe options. The Unsubscribe From All option should not only set all the subscription-related flags in Sales Cloud to false, but also set the subscriber’s status to Unsubscribed in Salesforce Marketing Cloud’s All Subscribers list. To achieve this, we need to log an UnsubEvent. In order to do that, we will add an additional button to the form (Unsubscribe From All) and a hidden parameter which will be passed if someone clicks this button (name="unsub" type="hidden" value="true"). After submitting the form, if unsub value equals true, we will log the UnsubEvent in addition to updating the flags in Sales/Service Cloud. The below is a simplified version of logging an UnsubEvent and it will unsubscribe the contact from all BUs – if you would like to modify it to your use case, refer to this article: Unsubscribe and Log an UnsubEvent with a LogUnsubEvent Execute Call. Here’s what we need to add to our script to make this part work:
Since we have the option to Unsubscribe From All, we now also have to add an option to Resubscribe. The Resubscribe option will set all the subscription-related flags in Sales Cloud to true and set the subscriber’s status to Active in Salesforce Marketing Cloud’s All Subscribers list. The Resubscribe button will appear for any contact that has the HasOptedOutOfEmail flag set to true in Sales Cloud. The button also has a hidden parameter that will be passed with the form (name="sub" type="hidden" value="true"). Upon clicking the button, we will invoke the update method on a subscriber object to set their status to Active in Marketing Cloud, as well as update their subscription-related flags in Sales Cloud:
Update subscriber’s data in Marketing Cloud
If you’re using Marketing Cloud Connect, a very important thing to remember when updating subscriber’s email address is to do it in both, Sales/Service Cloud and Marketing Cloud. Here is why:
If an email address for a Lead or Contact Object is updated in Sales Cloud or Service Cloud, the corresponding email address is not updated in the All Subscribers list.
Eliot Harper, THE DATA HANDBOOK – Data Architecture for Salesforce Marketing Cloud
In order to achieve this, we will add one more piece of a script to update the subscriber object. First we will check, if the subscriber’s current email address in Marketing Cloud is different from the one provided in the form, and if it is, we will update it accordingly:
You do not need to include the above if you already have a process in place that synchronizes email address changes from Sales/Service Cloud to All Subscribers list in Salesforce Marketing Cloud. If you’d like to learn more about synching updates between the clouds, read Markus Slabina’s blog post here.
Custom subscription and profile center full script
As a final touch, to improve the experience, let’s add a confirmation message and a button that will reload the page and display the updated data in the form. Here is the final version of the script, with all of the above changes included:
Remember, that you will need to use the CloudPagesURL function to link to the subscription center CloudPage from an email.
In order to see how the above script works, feel free to play around with one of my test contacts in the test version of the subscription and profile center that I set up on a CloudPage: https://pub.s10.exacttarget.com/
Here are some resources if you would like to read further about subscription management best practices:
Here you will find an interesting concept of creating Campaigns for each subscription and adding the Contact as a Campaign Member
Here you can read how Effective Email Preference Centers Help Keep Subscribers Active and Engaged
If you have a Salesforce Data Entry Event set up in Journey Builder that is not injecting records as intended, it is necessary to look into Debug Logs to determine what the cause may be. Here is a step-by-step guide to setting up and initiating Debug Logs for Journey Builder. The whole process takes part in Sales/Service Cloud, so ensure you have Admin permissions to be able to access Setup.
Turn on Marketing Cloud Connect request logs
In Sales/Service Cloud, click on the Marketing Cloud tab in the Salesforce Classic interface
Click Configure Marketing Cloud Connector on the right
In the Notifications section, click Initiate Log
Turn on Debug Logs
Go to Setup and in the Quick Find, search for Debug Logs
In the User Trace Flag section, click New
Set Traced Entity Type = User
Set Traced Entity Name to the user that will be creating/updating the record which fails being injected into the journey
Start and Expiration Dates should be set to start immediately and expire in the next hour, as the Marketing Cloud Connect activities can be logged only for 60 minutes at a time
Click New Debug Level
Give it a name and make sure there are no spaces
In the level settings, set Workflow = Finer and Callouts = Finest, leave the rest of the settings as they are and Save
Click Save and make sure your new Debug Level shows up in the Debug Level field, then click Save.
Create/Update your record
Now make sure that you are logged in as the User who was earlier selected in the Traced Entity Name and create or update your record so that it meets the entry criteria of the Journey. Document the date and time when the record was created or updated, and the ID of the record.
Parse the Debug Logs
Go to Setup and in the Quick Find, search for Debug Logs. The Debug Logs will be below the User Trace Flags section. There might be several logs, depending on the actions of the user, so having the timestamp that the record was created or updated will help narrow it down.
Use the View link to open the log(s) in a new tab. Search for JBSystemFlow_(object name) (i.e. JBSystemFlow_Contact). If you get a result, check the subsequent line with new_object in it to see if the Id lines up with the record created earlier, that should have been injected into the Journey. If so, you have found the correct log.
Next, search for a line that starts with FLOW_START_INTERVIEW_BEGIN and has JBSystemFlow_(Object). The lines between this and FLOW_START_INTERVIEW_END…JBSystemFlow_(Object) will give you all of the data in the fields for the new and old objects (old objects will only have data if a record is updated), plus all of the Decisions that the record went through in the associated Flow, plus the results for each outcome.
Each FLOW_ELEMENT_BEGIN/FLOW_ELEMENT_END and rows in between will show information about specific Decisions in the Flow, their Outcomes, and the results of those Outcomes.
Under the FLOW_START_INTERVIEW_END…JBSystemFlow(Object) line, if everything went well with the Flow, you will see a line for FLOW_BULK_ELEMENT_BEGIN…FireJBTrigger. If you see this line, unless there are several errors directly below, Salesforce ran the APEX job to fire the Entry Event. At this point, you would check the Marketing Cloud Connect logs to see if there was an issue with completing the call (click here to skip to this section of the article).
If you don’t see the FireJBTrigger line, copy the lines with decisions to a notepad.
Find the Flow associated with your Journey
Go to Setup, search for Flows in the Quick Find box and click Flows. Click Open next to the name of the Flow from the Debug Log (i.e. JBSystemFlow_Lead).
Once the page loads, you can drag the different nodes out to see the flow of the Decisions and Jobs. Note, that there is one Flow per Object that has at least one active Journey, which means there can be multiple Journeys referenced in one flow if more than one Journey is active on that Object. If you have a few different Journeys using, for example, Lead as the Object, you will have Decisions for the separate criteria. Sometimes a record may not pass the criteria for the Journey you are looking at but will continue through the Flow to see if it meets the criteria of other Journeys.
You will now have to find a Decision, where Name in the Decision lines up with the name at the end of the FLOW_ELEMENT_BEGIN. The second line after FLOW_ELEMENT_BEGIN, FLOW_RULE_DETAIL, will give you the name of the Outcome, and the results. The details of the Outcomes show up in the lower half of the Decision properties in the Flow. Focus only on the lines from the Debug Log that end with false, as those are the ones that did not pass the criteria. Here’s an example:
Once you are able to match the Decision Outcome(s) from the Flow canvas with the Decision(s) from Debug Log, you will be able to find out which criteria were not met and why the Flow stopped without injecting the record to the Journey.
Check the Marketing Cloud Connect logs
Navigate to the Documents object in the Salesforce Classic interface
Select the Marketing Cloud Documents folder
To view the log, select the log with the corresponding date
In the log, look out for any exceptions, here’s an example:
*****2019-10-08 09:51:24.680|LOG STARTED
*****2019-10-08 09:51:24.868|EXCEPTION|Expired access/refresh token.
SmartCapture forms provide a quick, user-friendly way to create simple forms and use them in Salesforce Marketing Cloud journeys, but they are not very versatile and often can create more problems than they actually solve.
In this tutorial, you will learn how to create a form using HTML and AMPscript and include functions that will let you quickly push the collected data into your instance of Sales/Service Cloud.
Create an HTML form
First, let’s create a very simple HTML form. If you’ve never created forms in HTML, you can start with reading this short overview on w3schools. The form action method attribute specifies how to send form-data. In this case, we are using post, which appends form-data inside the body of the HTTP request (data is not shown is in URL).
The RequestParameter('PAGEURL') function reloads the page when the form is submitted, posting the form parameters back to the same page, which are then retrieved by the RequestParameter() AMPscript functions. The form has a hidden submitted field. If this value is set to true, which it would after submitting the form, it will trigger the evaluation of the AMPscript functions. Here is a simplified diagram to help you understand this concept:
That’s why in the first step we check if the form has already been submitted or not. Let’s add the AMPscript functions to the form now.
Create form logic using AMPscript
Let’s start simple with creating a Sales Cloud Lead using the data collected in the form. The AMPscript needs to be placed at the top, as it should be evaluated upon form submission and prevent the form fields from being displayed after it’s been submitted. In the below script, we use the CreateSalesforceObject function to create a new Lead:
We can extend the logic a bit by checking first if the Lead with the given email address already exists in Sales Cloud, and if yes – updating their data, or if not – creating a new Lead:
Let’s now add the Lead to a Campaign in Sales Cloud. You will need to hardcode the Campaign Id into the script. Note that you cannot add the same Lead to a campaign twice, so if the Lead has already been added to the campaign, you will get an error. Let’s add creating a new Campaign Member to the script:
And now, let’s put the icing on the cake and send a confirmation email to the Lead. You will need to create a Triggered Send beforehand – if you’re not sure how, read my blog post: Send a triggered email using AMPscript. We will hardcode the Triggered Send external key as @ts_extkey, pass the Lead ID and Email Address to a new Subscriber object and invoke creation of a new Triggered Send object:
You now have a fully functional lead capture form integrated with Sales Cloud!
Smart Capture allows you to easily create forms on your Cloud Pages to collect information about your subscribers and then use that data for future sends and campaigns. While creating a Smart Capture form doesn’t require any coding skills and can be done using only the drag-and-drop editor, adding a simple script to your form can significantly increase the user experience. Forms prepopulated with data can be used for any type of campaign, as long as you already have some data about your subscriber in your database. Subscribers are more likely to register for an event or a raffle when they don’t need to manually fill in all the form fields, and the only thing they have to do is to submit the form.
Create a SmartCapture form
The first thing you will have to do is to create a Smart Capture form on your Cloud Page. Depending on your requirements, you can either create your own Data Extension to collect data submitted by your subscribers or use the system Data Extension called CloudPages_DataExtension.
For the purpose of this tutorial, let’s use the system data extension and create a very simple form with three fields: First Name, Last Name and Email Address.
Add AMPscript to retrieve Salesforce data
In this example, we will be retrieving Sales Cloud data to prepopulate the form using the RetrieveSalesforceObjects function. We will be looking up Contacts in Sales Cloud based on the Subscriber Key. Add the following code in a separate content area, above your Smart Capture form:
If you’re using Campaigns in Sales Cloud, which can admit both Contacts and Leads, you can extend your code with a Substring function, so that it’s able to correctly process both:
You can also use data stored in Marketing Cloud to prefill the form – just remember, that you will need to use the LookupRows function instead of RetrieveSalesforceObjects.
Prepopulate the data in the form
In order to add the data retrieved from Salesforce to your form, you will have to modify each of the form input fields separately. Click once on the Smart Capture form, and then once again on the field you wish to modify.
Now edit the field in the HTML view and add an inline display of the adequate field retrieved from Sales Cloud as the default value at the end of the HTML input tag:
Do this for all the fields that should be prepopulated with data. Publish your CloudPage and test it – the fastest way to test the form is to create an email with a button leading to your CloudPage and previewing the email against a subscriber, who is present in your Salesforce database.
You can also connect this form to a journey in Journey Builder to send a confirmation email to anyone who filled it in, update their Salesforce data or add them to a consecutive campaign.
Marketing Cloud Connect integrates your Salesforce Marketing Cloud instance with Salesforce Sales, Service, and Community Clouds. It’s an easy-to-configure set of functionality that can bring great benefits to your organization. There is an official Marketing Cloud Connect troubleshooting guide available, but I’ve decided to share a few tips and tricks that usually solve most common connection problems.
To be able to correctly troubleshoot Marketing Cloud Connect, you will need the credentials of your system users, which are used to establish the connection between the clouds – your Salesforce System User (API User) and Marketing Cloud API User.
What is also very important, is to make sure that you are logged out of any active Marketing Cloud and Sales Cloud sessions – this is a rookie mistake, which leads to connecting both clouds using a “regular” user, instead of the dedicated Marketing Cloud API user. The best way to avoid making this mistake is to always use the Incognito Mode when working with Marketing Cloud Connect API users.
Change API user
You may receive an email from the Marketing Cloud Connect managed package with the subject: “Salesforce Marketing Cloud Connect – Action Required to Prevent Service Interruption.” This email would be sent if the package detects an issue when trying to connect your Salesforce org with your Marketing Cloud account through the Marketing Cloud Connect API User. To avoid interruption of service with Marketing Cloud Connect, reconnect your Marketing Cloud Connect API User:
Log into your Sales or Service Cloud org as the System User (API User)
Switch to Salesforce Classic interface
Navigate to the Marketing Cloud tab
Re-enter your Marketing Cloud API user credentials
It is possible, however, that the system won’t let you reconnect the API user and you will see the following error message:
Sorry, something went wrong. We couldn’t retrieve the API User details. Try again or open a support case in the Help and Training portal.
In that case, follow these steps to reconnect your Salesforce System User (API User) without the need to delete the Connector Configuration:
Login to Sales Cloud Org – as the System User (API User)
In the quick find search box type in ‘Visualforce Pages’
There are multiple scenarios where it’s necessary to remove the mapping between a Marketing Cloud User and a Salesforce User related to MC Connect, for example, if the user accidentally entered the wrong username/password when they first mapped their orgs; if permissions for a User on the Marketing Cloud side have changed; or if OAuth token is stored in Salesforce, but User is still prompted for Username and Password when selecting the Marketing Cloud Tab in Sales/Service Cloud.
Proceed with the following steps to clear OAuth tokens:
Log in to Salesforce using an incognito (private) browser session.
Select your Username in the upper right-hand corner, then select Developer Console.
Note: Replace the Id_of_System_User in the code above with the Salesforce ID of your system user; replace MID with MID of the integrated Business Unit in Marketing Cloud. Use only MIDs relevant to your connection.
Afterwards, use the incognito window to access the ‘Marketing Cloud’ tab again. This should reconnect your user using the correct token.