Custom profile and subscription center integrated with Sales/Service Cloud

In this tutorial, you will learn how to create a simple, yet fully customizable profile and subscription center integrated with Sales and Service Cloud. If you would like to skip the reading and jump to the final version of the script, click here. Bear in mind, that the script utilizes a couple of standard and custom Sales/Service Cloud fields – the full list can be found here.

What are Profile and Subscription Centers?

Each instance of Salesforce Marketing Cloud comes with a standard, predefined Profile Center and Subscription Center.

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.

Anatomy of a Subscription Center

A Subscription Center is nothing else but an HTML form. The data passed in the form is then processed by a script – in this tutorial, we will use AMPscript. If you’ve never created a form before, you might want to check out this article first: Create a Sales Cloud-integrated lead capture form using AMPscript.

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:

Field LabelAPI Field NameTypeLength
Contact IDIdid18
EmailEmailemail80
Email Opt OutHasOptedOutOfEmailboolean
Name FirstNamestring80
Name LastNamestring80
NewsletterNewsletter__cboolean
EventsEvents__cboolean
OffersOffers__cboolean

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
  • Solve problems using the subscription-center and preference-center tags on Salesforce Stack Exchange

Questions? Comments?

Leave a comment below or email me at zuzanna@sfmarketing.cloud.

Troubleshooting Journey Builder Integration with Debug Logs

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

  1. In Sales/Service Cloud, click on the Marketing Cloud tab in the Salesforce Classic interface
  2. Click Configure Marketing Cloud Connector on the right
  3. In the Notifications section, click Initiate Log

Turn on Debug Logs

  1. Go to Setup and in the Quick Find, search for Debug Logs
  2. In the User Trace Flag section, click New
  3. Set Traced Entity Type = User
  1. Set Traced Entity Name to the user that will be creating/updating the record which fails being injected into the journey
  2. 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
  3. Click New Debug Level
  4. Give it a name and make sure there are no spaces
  1. In the level settings, set Workflow = Finer and Callouts = Finest, leave the rest of the settings as they are and Save
  1. 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.

Here’s an example:

16:23:37.142 (150821372)|FLOW_START_INTERVIEW_BEGIN|8557980ff96eae468bac8498796162d5d1cd65-6ef6|JBSystemFlow_Lead
16:23:37.142  16:23:37.142
(151572909)|FLOW_ELEMENT_BEGIN|8557980ff96eae468bac8498796162d5d1cd65-6ef6|FlowDecision|JB_SalesforceObj2d95094362a61233d7e7d05c70c5bd3a_Decision 16:23:37.142
(151749528)|FLOW_RULE_DETAIL|8557980ff96eae468bac8498796162d5d1cd65-6ef6|SalesforceObj2d95094362a61233 (151839236)|FLOW_START_INTERVIEW_END|8557980ff96eae468bac8498796162d5d1cd65-6ef6|JBSystemFlow_Lead

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:

16:23:37.142 (151572909)|FLOW_ELEMENT_BEGIN|8557980ff96eae468bac8498796162d5d1cd65-6ef6|FlowDecision|JB_SalesforceObj2d95094362a61233d7e7d05c70c5bd3a_Decision 16:23:37.142 (151749528)|FLOW_RULE_DETAIL|8557980ff96eae468bac8498796162d5d1cd65-6ef6|SalesforceObj2d95094362a61233d7e7d05c70c5bd3a|false 

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

  1. Navigate to the Documents object in the Salesforce Classic interface
  2. Select the Marketing Cloud Documents folder
  3. Click Go!
  1. 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.680|PROCESS|SecureSettingsManager 
*****2019-10-08 09:51:24.868|EXCEPTION|Expired access/refresh token.

If you see an exception related to the access token, resolve it by clearing out User Mappings and OAuth Tokens in Marketing Cloud Connect.

If there are other exceptions or errors visible in the log which you are unable to interpret yourself, it’s best to send them over to Support and ask for assistance in further troubleshooting.

Sources: https://help.salesforce.com/articleView?id=000314336&type=1&mode=1, https://help.salesforce.com/articleView?id=000314349&language=en_US&type=1&mode=1, https://help.salesforce.com/articleView?id=mc_co_initiate_log.htm&type=5, https://help.salesforce.com/articleView?id=000320849&type=1&mode=1

Troubleshooting Marketing Cloud Connect

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:

  1. Log into your Sales or Service Cloud org as the System User (API User)
  2. Switch to Salesforce Classic interface
  3. Navigate to the Marketing Cloud tab
  4. 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:

  1. Login to Sales Cloud Org – as the System User (API User)
  2. Click Setup
  3. In the quick find search box type in ‘Visualforce Pages’
  4. Click on ‘Visualforce Pages
  5. Locate the label for ‘ChangeAPIUser
  6. Click on that label
  7. Click on the ‘Preview‘ button
  8. Click ‘Connect to Marketing Cloud‘ button

Source: https://help.salesforce.com/articleView?id=000318452&type=1&mode=1

Clearing out User Mappings and OAuth tokens

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:

  1. Log in to Salesforce using an incognito (private) browser session.
  2. Select your Username in the upper right-hand corner, then select Developer Console.
  3. Click Debug, then select Execute anonymous window
  4. Execute the following Code, each line separately:
et4ae5.SupportUtilities.deleteUserTokens('Id_of_System_User');  
et4ae5.SupportUtilities.deleteUserTokens('Id_of_System_User|Parent_BU_MID');
et4ae5.SupportUtilities.deleteUserTokens('Id_of_System_User|Default_BU_MID'); 
et4ae5.SupportUtilities.deleteUserTokens('APIUSER');
et4ae5.SupportUtilities.deleteUserTokens('APIUSER|Parent_BU_MID');
et4ae5.SupportUtilities.deleteUserTokens('APIUSER|Default_BU_MID'); 

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. 

Source: https://help.salesforce.com/articleView?id=000336685&type=1&mode=1

Clearing Marketing Cloud Connect Configuration

If none of the above helped, you can try clearing the Marketing Cloud Connect configuration and re-configuring it from scratch.

As a first step, you will have to add the “Configurations” tab to your Sales/Service Cloud:

  1. Click Setup
  2. Follow the steps based on your UI:
    • Salesforce Classic: Under the “Create” category, select Tabs
    • Salesforce Lightning: Under the “User Interface” category, select Tabs
  3. Click New
  4. Choose “Configurations” from the Object drop-down menu
  5. Pick any Tab style
  6. Click Next > Next > Save

Once the tab has been added, navigate to it by clicking the Plus symbol on the tab bar and click on the Configurations link. Now delete the existing configuration:

  1. Choose All under the “View” drop-down, and then click Go
  2. Delete the existing Configuration Object

Now you are ready to re-configure Marketing Cloud Connect:

  1. Click the Marketing Cloud tab
  2. Enter the Marketing Cloud API Username and Password
  3. Select values for Send Types, Target Audience, Exclusion Audience, Support Ticket Recipient, and Tracking Preferences
  4. Click Marketing Cloud Tab once more, re-integrate individual Users as needed

Source: https://help.salesforce.com/articleView?id=000337425&type=1&mode=1