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 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.

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:

<html>
<body>
<h2>Update your profile:</h2>
<form>
<label>First name: </label><input type="text" name="firstname"><br>
<label>Last name: </label><input type="text" name="lastname"><br>
<label>Email: </label><input type="text" name="email"><br>
<h2>Update your subscriptions:</h2>
<label>Newsletter: </label><input name="newsletter" type="checkbox"><br>
<label>Events: </label><input name="events" type="checkbox"><br>
<label>Offers: </label><input name="offers" type="checkbox"><br>
<input name="submitted" type="hidden" value="true"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

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:

%%[
SET @contactId = _subscriberkey
IF NOT EMPTY(@contactId) THEN
/* fetch data from Sales Cloud to show in the form */
SET @subscriberRows = RetrieveSalesforceObjects(
"Contact",
"Id,FirstName,LastName,Email,Newsletter__c,Events__c,Offers__c,HasOptedOutOfEmail",
"Id", "=", @contactId
)
IF RowCount(@subscriberRows) > 0 THEN
SET @row = row(@subscriberRows,1)
SET @FirstName = field(@row,"FirstName")
SET @LastName = field(@row,"LastName")
SET @Email = field(@row,"Email")
SET @Newsletter = field(@row,"Newsletter__c")
SET @Events = field(@row,"Events__c")
SET @Offers = field(@row,"Offers__c")
SET @HasOptedOutOfEmail = field(@row,"HasOptedOutOfEmail")
IF @Newsletter == true THEN SET @Newsletterchk = "checked" ENDIF
IF @Events == true THEN SET @Eventschk = "checked" ENDIF
IF @Offers == true THEN SET @Offerschk = "checked" ENDIF
]%%
<h2>Update your profile:</h2>
<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<label>First name: </label><input type="text" name="firstname" value="%%=v(@FirstName)=%%"><br>
<label>Last name: </label><input type="text" name="lastname" value="%%=v(@LastName)=%%"><br>
<label>Email: </label><input type="text" name="email" value="%%=v(@Email)=%%"><br>
<h2>Update your subscriptions:</h2>
<label>Newsletter: </label><input name="newsletter" type="checkbox" %%=v(@Newsletterchk)=%%><br>
<label>Events: </label><input name="events" type="checkbox" %%=v(@Eventschk)=%%><br>
<label>Offers: </label><input name="offers" type="checkbox" %%=v(@Offerschk)=%%><br>
<input name="submitted" type="hidden" value="true"><br>
<input type="submit" value="Submit">
</form>
%%[ELSE]%%
Sorry, something went wrong (no records found).
%%[ENDIF ELSE]%%
Sorry, something went wrong (missing subscriber key).
%%[ENDIF]%%

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:

%%[
SET @contactId = _subscriberkey
IF RequestParameter("submitted") == true THEN
/* update contact */
SET @updateRecord = UpdateSingleSalesforceObject(
"Contact", @contactId,
"FirstName", RequestParameter("firstname"),
"LastName", RequestParameter("lastname"),
"Email", RequestParameter("email"),
"Newsletter__c", Iif(RequestParameter("newsletter") == "on", "true", "false"),
"Events__c", Iif(RequestParameter("events") == "on", "true", "false"),
"Offers__c", Iif(RequestParameter("offers") == "on", "true", "false")
)
Output(v('<font color="green">Contact has been updated succesfully.</font><br>'))
ENDIF
IF NOT EMPTY(@contactId) THEN
/* fetch data from Sales Cloud to show in the form */
SET @subscriberRows = RetrieveSalesforceObjects(
"Contact",
"Id,FirstName,LastName,Email,Newsletter__c,Events__c,Offers__c,HasOptedOutOfEmail",
"Id", "=", @contactId
)
IF RowCount(@subscriberRows) > 0 THEN
SET @row = row(@subscriberRows,1)
SET @FirstName = field(@row,"FirstName")
SET @LastName = field(@row,"LastName")
SET @Email = field(@row,"Email")
SET @Newsletter = field(@row,"Newsletter__c")
SET @Events = field(@row,"Events__c")
SET @Offers = field(@row,"Offers__c")
SET @HasOptedOutOfEmail = field(@row,"HasOptedOutOfEmail")
IF @Newsletter == true THEN SET @Newsletterchk = "checked" ENDIF
IF @Events == true THEN SET @Eventschk = "checked" ENDIF
IF @Offers == true THEN SET @Offerschk = "checked" ENDIF
]%%
<h2>Update your profile:</h2>
<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<label>First name: </label><input type="text" name="firstname" value="%%=v(@FirstName)=%%"><br>
<label>Last name: </label><input type="text" name="lastname" value="%%=v(@LastName)=%%"><br>
<label>Email: </label><input type="text" name="email" value="%%=v(@Email)=%%"><br>
<h2>Update your subscriptions:</h2>
<label>Newsletter: </label><input name="newsletter" type="checkbox" %%=v(@Newsletterchk)=%%><br>
<label>Events: </label><input name="events" type="checkbox" %%=v(@Eventschk)=%%><br>
<label>Offers: </label><input name="offers" type="checkbox" %%=v(@Offerschk)=%%><br>
<input name="submitted" type="hidden" value="true"><br>
<input type="submit" value="Submit">
</form>
%%[ELSE]%%
Sorry, something went wrong (no records found).
%%[ENDIF ELSE]%%
Sorry, something went wrong (missing subscriber key).
%%[ENDIF]%%

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:

IF RequestParameter("submitted") == true AND RequestParameter("unsub") == true THEN
/* update contact in Sales Cloud */
SET @updateRecord = UpdateSingleSalesforceObject(
"Contact", @contactId,
"Newsletter__c", "false",
"Events__c", "false",
"Offers__c", "false",
"HasOptedOutOfEmail", "true"
)
/* log unsubscribe event to mark as unsubscribed in All Subscribers */
SET @reason = "Unsubscribed through custom subscription center"
SET @lue = CreateObject("ExecuteRequest")
SETObjectProperty(@lue,"Name","LogUnsubEvent")
SET @lue_prop = CreateObject("APIProperty")
SETObjectProperty(@lue_prop, "Name", "SubscriberKey")
SETObjectProperty(@lue_prop, "Value", @contactId)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)
SET @lue_prop = CreateObject("APIProperty")
SETObjectProperty(@lue_prop, "Name", "Reason")
SETObjectProperty(@lue_prop, "Value", @reason)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)
SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)

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:

ELSEIF RequestParameter("submitted") == true AND RequestParameter("sub") == true THEN
/* update contact in Sales Cloud */
SET @updateRecord = UpdateSingleSalesforceObject(
"Contact", @contactId,
"FirstName", RequestParameter("firstname"),
"LastName", RequestParameter("lastname"),
"Email", RequestParameter("email"),
"Newsletter__c", "true",
"Events__c", "true",
"Offers__c", "true",
"HasOptedOutOfEmail", "false"
)
/* set subscriber status to active in All Subscribers */
SET @email = RequestParameter("email")
SET @Subscriber = CreateObject("Subscriber")
SetObjectProperty(@Subscriber, "SubscriberKey", @contactId)
SetObjectProperty(@Subscriber, "EmailAddress", @email)
SetObjectProperty(@Subscriber, "Status", "Active" )
SET @Status = InvokeUpdate(@Subscriber, @createErrDesc, @createErrNo, @createOpts)

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:

/* update email in All Subscribers list */
IF RequestParameter("email") != AttributeValue("emailaddr") THEN
SET @email = RequestParameter("email")
SET @Subscriber = CreateObject("Subscriber")
SetObjectProperty(@Subscriber, "SubscriberKey", @contactId)
SetObjectProperty(@Subscriber, "EmailAddress", @email)
SET @Status = InvokeUpdate(@Subscriber, @createErrDesc, @createErrNo, @createOpts)
ENDIF

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:

<!––– Copyright © 2020 Zuzanna Jarczynska http://sfmarketing.cloud –––>
%%[
SET @contactId = _subscriberkey
IF NOT EMPTY(@contactId) THEN
/* fetch data from Sales Cloud to show in the form */
SET @subscriberRows = RetrieveSalesforceObjects(
"Contact",
"Id,FirstName,LastName,Email,Newsletter__c,Events__c,Offers__c,HasOptedOutOfEmail",
"Id", "=", @contactId
)
IF RowCount(@subscriberRows) > 0 THEN
SET @row = row(@subscriberRows,1)
SET @FirstName = field(@row,"FirstName")
SET @LastName = field(@row,"LastName")
SET @Email = field(@row,"Email")
SET @Newsletter = field(@row,"Newsletter__c")
SET @Events = field(@row,"Events__c")
SET @Offers = field(@row,"Offers__c")
SET @HasOptedOutOfEmail = field(@row,"HasOptedOutOfEmail")
IF @Newsletter == true THEN SET @Newsletterchk = "checked" ENDIF
IF @Events == true THEN SET @Eventschk = "checked" ENDIF
IF @Offers == true THEN SET @Offerschk = "checked" ENDIF
ELSE
]%%
Sorry, something went wrong (no records found).
%%[
ENDIF
ELSE
]%%
Sorry, something went wrong (missing subscriber key).
%%[
ENDIF
IF RequestParameter("submitted") == true AND RequestParameter("unsub") == true THEN
/* update contact in Sales Cloud */
SET @updateRecord = UpdateSingleSalesforceObject(
"Contact", @contactId,
"Newsletter__c", "false",
"Events__c", "false",
"Offers__c", "false",
"HasOptedOutOfEmail", "true"
)
/* log unsubscribe event to mark as unsubscribed in All Subscribers */
SET @reason = "Unsubscribed through custom subscription center"
SET @lue = CreateObject("ExecuteRequest")
SETObjectProperty(@lue,"Name","LogUnsubEvent")
SET @lue_prop = CreateObject("APIProperty")
SETObjectProperty(@lue_prop, "Name", "SubscriberKey")
SETObjectProperty(@lue_prop, "Value", @contactId)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)
SET @lue_prop = CreateObject("APIProperty")
SETObjectProperty(@lue_prop, "Name", "Reason")
SETObjectProperty(@lue_prop, "Value", @reason)
AddObjectArrayItem(@lue, "Parameters", @lue_prop)
SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)
ELSEIF RequestParameter("submitted") == true AND RequestParameter("sub") == true THEN
/* update contact in Sales Cloud */
SET @updateRecord = UpdateSingleSalesforceObject(
"Contact", @contactId,
"FirstName", RequestParameter("firstname"),
"LastName", RequestParameter("lastname"),
"Email", RequestParameter("email"),
"Newsletter__c", "true",
"Events__c", "true",
"Offers__c", "true",
"HasOptedOutOfEmail", "false"
)
/* set subscriber status to active in All Subscribers */
SET @email = RequestParameter("email")
SET @Subscriber = CreateObject("Subscriber")
SetObjectProperty(@Subscriber, "SubscriberKey", @contactId)
SetObjectProperty(@Subscriber, "EmailAddress", @email)
SetObjectProperty(@Subscriber, "Status", "Active" )
SET @Status = InvokeUpdate(@Subscriber, @createErrDesc, @createErrNo, @createOpts)
/* fetch updated data to show in the form */
SET @subscriberRows = RetrieveSalesforceObjects(
"Contact",
"Id,FirstName,LastName,Email,Newsletter__c,Events__c,Offers__c,HasOptedOutOfEmail",
"Id", "=", @contactId
)
SET @row = row(@subscriberRows,1)
SET @FirstName = field(@row,"FirstName")
SET @LastName = field(@row,"LastName")
SET @Email = field(@row,"Email")
SET @Newsletter = field(@row,"Newsletter__c")
SET @Events = field(@row,"Events__c")
SET @Offers = field(@row,"Offers__c")
SET @HasOptedOutOfEmail = field(@row,"HasOptedOutOfEmail")
IF @Newsletter == true THEN SET @Newsletterchk = "checked" ENDIF
IF @Events == true THEN SET @Eventschk = "checked" ENDIF
IF @Offers == true THEN SET @Offerschk = "checked" ENDIF
ELSEIF RequestParameter("submitted") == true THEN
/* update contact */
SET @updateRecord = UpdateSingleSalesforceObject(
"Contact", @contactId,
"FirstName", RequestParameter("firstname"),
"LastName", RequestParameter("lastname"),
"Email", RequestParameter("email"),
"Newsletter__c", Iif(RequestParameter("newsletter") == "on", "true", "false"),
"Events__c", Iif(RequestParameter("events") == "on", "true", "false"),
"Offers__c", Iif(RequestParameter("offers") == "on", "true", "false")
)
/* update email in All Subscribers list */
IF RequestParameter("email") != AttributeValue("emailaddr") THEN
SET @email = RequestParameter("email")
SET @Subscriber = CreateObject("Subscriber")
SetObjectProperty(@Subscriber, "SubscriberKey", @contactId)
SetObjectProperty(@Subscriber, "EmailAddress", @email)
SET @Status = InvokeUpdate(@Subscriber, @createErrDesc, @createErrNo, @createOpts)
ENDIF
ENDIF
IF @HasOptedOutOfEmail == true THEN
]%%
<h2>Update your profile:</h2>
<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<label>First name: </label><input type="text" name="firstname" value="%%=v(@FirstName)=%%"><br>
<label>Last name: </label><input type="text" name="lastname" value="%%=v(@LastName)=%%"><br>
<label>Email: </label><input type="text" name="email" value="%%=v(@Email)=%%"><br>
<h2>Resubscribe</h2>
You have unsubscribed from ALL publications from <i>%%member_busname%%</i>. If you wish to resubscribe, click the Resubscribe button below.
<input name="submitted" type="hidden" value="true"><br>
<input name="sub" type="hidden" value="true"><br><br>
<input type="submit" value="Resubscribe">
</form>
%%[ELSEIF RequestParameter("submitted") == false AND NOT EMPTY(@contactId) AND RowCount(@subscriberRows) > 0 THEN]%%
<h2>Update your profile:</h2>
<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<label>First name: </label><input type="text" name="firstname" value="%%=v(@FirstName)=%%"><br>
<label>Last name: </label><input type="text" name="lastname" value="%%=v(@LastName)=%%"><br>
<label>Email: </label><input type="text" name="email" value="%%=v(@Email)=%%"><br>
<h2>Update your subscriptions:</h2>
<label>Newsletter: </label><input name="newsletter" type="checkbox" %%=v(@Newsletterchk)=%%><br>
<label>Events: </label><input name="events" type="checkbox" %%=v(@Eventschk)=%%><br>
<label>Offers: </label><input name="offers" type="checkbox" %%=v(@Offerschk)=%%><br>
<input name="submitted" type="hidden" value="true"><br>
<input type="submit" value="Submit"></form>
<br><br>
<h2>Unsubscribe From All</h2>
If you wish to unsubscribe from ALL publications from <i>%%member_busname%%</i>, click the Unsubscribe From All button below.
<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<input name="submitted" type="hidden" value="true">
<input name="unsub" type="hidden" value="true"><br>
<input type="submit" value="Unsubscribe From All"></form>
%%[ELSEIF RequestParameter("submitted") == true AND NOT EMPTY(@contactId) THEN]%%
<h2>Your profile has been updated.</h2>
Go back to your profile.<br>
<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<br>
<input type="submit" value="Go Back"></form>
%%[ENDIF]%%

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.

32 thoughts on “Custom profile and subscription center integrated with Sales/Service Cloud

  1. seancarew

    This is great. I love the way the form works. I get the error that…

    Sorry, something went wrong (missing subscriber key).

    How do I pass subscriber/contactkey securely to the page?

    I’d like it to look like ?qs=1231314324.. instead of the actual contact key.

    Thank you for again for posting.

    Like

      1. Bhawani

        Hi Zuzanna,

        I have simply created a landing page name “Testpage” and put the code which is provided by you and when I am publishing the code it’s giving the error: Sorry, something went wrong (missing subscriber key).

        2. Can I use Lead instead of contact with the same code or I need to do some manual steps as well as we are using the lead object?

        Thanks,
        Bhawani

        Like

      2. You need to test the CloudPage against an actual subscriber – the way you’re testing it now, it’s not able to “do” anything because there is no subscriber – thus the message about a missing subscriber key. Best would be to build a simple email with a button leading to that CloudPage and preview the email against an actual subscriber. Here you can find more details: https://help.salesforce.com/articleView?id=mc_es_subscriber_preview_test_send.htm&type=5

        Like

      3. Bhawani

        Hi Zuzanna,

        Thank you for taking the time to help me, it really meant a lot. I am able to test now. I have one question: I have one custom field in the salesforce “opt-In” and want to use for subscribe and unsub form marketing cloud as well as in salesforce. Please can you let me know how I can use this field so on this field basis I want to update this field in subscriber as well in Salesforce?

        Thanks,
        Bhawani

        Like

      4. Hi Bhawani – it’s all described in the article: “Additionally, I have added three read-only checkboxes to the Contact object for subscription management: Newsletter, Offers and Events.” – if you only need one, you can take the other two out from the script and update the one left with the API name of your custom filed.

        Like

  2. seancarew

    I placed the code on a landing page. Using %%=CloudPagesURL(123)=%% to create a link for the email, with the actual page Id of course, I am getting a Server 500 error… What am I missing? my old pref center needed a Mid code… I think I’m pretty close.

    Like

    1. Hi Sean – this is correct, you need to use the CloudPagesURL function to redirect subscribers from the email to your landing page. Using this function will ensure that all the required parameters are passed correctly. If you’re getting the 500 error – could you please verify that you have the following fields available in your Sales Cloud instance: https://sfmarketing.cloud/2020/01/14/custom-profile-and-subscription-center-integrated-with-sales-service-cloud/#fields. If this doesn’t help, you can wrap the whole script on the landing page in a try/catch statement, which should help you debug. Here is the updated version of the script, with the debugging added: https://gist.github.com/zuzannamj/ff92706f9ab4882a48b748d267dec22b

      Like

      1. seancarew

        Thank you – Yes, that was the issue! I added the fields and it works. I am currently trying to create publication list linkage. Any thoughts?

        Like

      2. To interact with Publication Lists, you will need to use Salesforce Marketing Cloud’s SOAP API. Here’s a sample script to retrieve all public Publication Lists from an account: https://gist.github.com/zuzannamj/bef4c040a9402461aa16b989943d9343. In order to update a subscriber’s status on a Publication List, you would have to use the InvokeUpdate method, just like we did in the Subscription Center script to update a subscriber’s status and email address on All Subscribers list. I will consider writing another article to address this topic.

        Like

  3. Alexander

    Hi!
    Thank you!
    It works like magic!
    One thing. When the user clicked unsubscribe this action is not tracked by the send report – Inbox Activity – unsubscribes.

    Is it possible to bypass this limitation?

    Like

    1. Hi Luiz – if you’re using your own unsubscribe process / subscription center, you need to contact support and ask them to abolish the process of checking email compliance with CAN-SPAM act. After that, you will be able to send out emails without the %%profile_center_url%% and other mandatory strings.

      Like

  4. paulina

    Hi! Really interesting blog, I’m very impressed! I have the following question. I want to add additional page before passing data to Salesforce, whenever somebody decides to click unsubscribe from all, in order to ask customer if they really want to unsubscribe from all communication. In this second page they can select Submit or Cancel, where Submit will be pass data to Sales Cloud and Cancel will redirect back to profile (without any changes).

    Like

    1. Hi Paulina!

      This is possible, even using the one-page approach that I used in the article.

      Currently, when someone click “Unsubscribe from all” this script gets resolved:

      IF RequestParameter(“submitted”) == true AND RequestParameter(“unsub”) == true THEN

      /* update contact in Sales Cloud */
      SET @updateRecord = UpdateSingleSalesforceObject(
      “Contact”, @contactId,
      “Newsletter__c”, “false”,
      “Events__c”, “false”,
      “Offers__c”, “false”,
      “HasOptedOutOfEmail”, “true”
      )

      /* log unsubscribe event to mark as unsubscribed in All Subscribers */
      SET @reason = “Unsubscribed through custom subscription center”

      SET @lue = CreateObject(“ExecuteRequest”)
      SETObjectProperty(@lue,”Name”,”LogUnsubEvent”)

      SET @lue_prop = CreateObject(“APIProperty”)
      SETObjectProperty(@lue_prop, “Name”, “SubscriberKey”)
      SETObjectProperty(@lue_prop, “Value”, @contactId)
      AddObjectArrayItem(@lue, “Parameters”, @lue_prop)

      SET @lue_prop = CreateObject(“APIProperty”)
      SETObjectProperty(@lue_prop, “Name”, “Reason”)
      SETObjectProperty(@lue_prop, “Value”, @reason)
      AddObjectArrayItem(@lue, “Parameters”, @lue_prop)

      SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)

      To add an additional step, you would have to replace the code inside this condition with two buttons:

      IF RequestParameter(“submitted”) == true AND RequestParameter(“unsub”) == true THEN]%%

      <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
      <input name="submitted" type="hidden" value="true">
      <input name="unsuball" type="hidden" value="true"><br>
      <input type="submit" value="Unsubscribe From All"></form>

      <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
      <input type="submit" value="Cancel"></form>

      And add an additional condition to be resolved if someone clicks on “Unsubscribe from all”:

      ELSEIF RequestParameter(“submitted”) == true AND RequestParameter(“unsuball”) == true THEN

      /* update contact in Sales Cloud */
      SET @updateRecord = UpdateSingleSalesforceObject(
      “Contact”, @contactId,
      “Newsletter__c”, “false”,
      “Events__c”, “false”,
      “Offers__c”, “false”,
      “HasOptedOutOfEmail”, “true”
      )

      /* log unsubscribe event to mark as unsubscribed in All Subscribers */
      SET @reason = “Unsubscribed through custom subscription center”

      SET @lue = CreateObject(“ExecuteRequest”)
      SETObjectProperty(@lue,”Name”,”LogUnsubEvent”)

      SET @lue_prop = CreateObject(“APIProperty”)
      SETObjectProperty(@lue_prop, “Name”, “SubscriberKey”)
      SETObjectProperty(@lue_prop, “Value”, @contactId)
      AddObjectArrayItem(@lue, “Parameters”, @lue_prop)

      SET @lue_prop = CreateObject(“APIProperty”)
      SETObjectProperty(@lue_prop, “Name”, “Reason”)
      SETObjectProperty(@lue_prop, “Value”, @reason)
      AddObjectArrayItem(@lue, “Parameters”, @lue_prop)

      SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)

      Hope this helps 🙂

      Like

  5. Hi Zuzanna –

    How do you deal with sending an email to the first time? Do you default all of the checkboxes in Salescloud to true? We currently use publication lists, but are moving away from that. So if I was going to send an email to the “events” list using a data extension. In the publication list model, it would add them to the list. How do you “opt-in” the contact and check that box in Salescloud?

    Like

    1. Hi Evan – I always set up a double opt-in process, which means that when a subscriber signs up for a newsletter/subscription, either using a webform or during a phone call with a sales agent, or any other way – this would trigger sending the double opt-in email for that particular newsletter/subscription type, and once they confirm, the relevant checkbox would be checked in Salesforce and depending on whether you are using Data Extensions or Publication lists, they would be added to that DE or list.

      Like

  6. Paula

    Hey Zuzanna, i have a question. I used tour script and working properly. However I have another functionality that I tried to add, when somebody untick all of the preferences, should be redirected to the page where will be question “do you want to unsubscribe” yes/no. If yes all values will be empty and master unsub. But if not, he should come back to orginal preference center with old values (not empty). I tested it with request parameter == or != but is not working. Do you have an idea if it can be done via amp?

    Like

    1. Hi Paula – yes, this can be done using AMPscript. You would need to add a few more variables (depending on how many checkboxes you have), for example, if you have a @Newsletter variable you could add an additional variable called @OldNewsletter or something similar and store the “original” preferences for that person in that variable. Then, using the same logic you would use to switch between different pages, pass those along as hidden form fields and if they eventually come back to the original preference centre, retrieve them as you would for the “normal” checkboxes, so: SET @Newsletter = RequestParameter(“OldNewsletter”). Hope this helps 🙂

      Like

  7. Hi Zuzanna

    Thank you for your blog, your articles are very helpful. I have used this article to create a custom subscription centre for the company I work for but I am having an unexpected result from a call to the Marketing Cloud API ListSubscriber object.

    I am attempting to query the ListSubscriber object for the subscription status as documented here: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/retrieving_all_lists_a_subscriber_is_on.htm.

    The user is subscribed to 5 publication lists, 4 of which are public and 1 private.

    This is the code I am using to make the API call.

    /* users subscription status info */
    var @rrsub, @sfpsub, @substatus

    SET @rrsub = CreateObject(“RetrieveRequest”)
    SetObjectProperty(@rrsub,”ObjectType”,”ListSubscriber”)
    AddObjectArrayItem(@rrsub, “Properties”, “ListID”)
    AddObjectArrayItem(@rrsub, “Properties”, “SubscriberKey”)
    AddObjectArrayItem(@rrsub, “Properties”, “Status”)

    SET @sfpsub = CreateObject(“SimpleFilterPart”)
    SetObjectProperty(@sfpsub,”Property”,”SubscriberKey”)
    SetObjectProperty(@sfpsub,”SimpleOperator”,”equals”)
    AddObjectArrayItem(@sfpsub,”Value”,@email)

    SetObjectProperty(@rrsub,”Filter”,@sfpsub)
    SET @substatus = InvokeRetrieve(@rrsub, @status, @requestID)
    output(concat(“rrSubStatus: “, @status))
    output(concat(“rrSubRequestID: “, @requestID))

    for @i = 1 to RowCount(@substatus) do
    set @substat = Row(@substatus, @i)
    set @ListID = Field(@substat, “ListID”)
    set @SubscriberKey = Field(@substat, “SubscriberKey”)
    set @Status = Field(@substat, “Status”)

    output(concat(“ListID: “, @ListID))
    output(concat(“SubscriberKey: “, @SubscriberKey))
    output(concat(“Status: “, @Status))
    next @i

    This is the information being returned by the API call.
    rrSubStatus: OK
    rrSubRequestID: 1e8d1b43-679c-40a1-bebc-xxxxxxxxxxxx
    ListID: 102
    SubscriberKey: xxxxxxx@gmail.com
    Status: Active
    ListID: 409
    SubscriberKey: xxxxxxx@gmail.com
    Status: Active

    There are only two list ID’s returned, ID: 102 is the All Subscribers list and ID: 409 is the private publication list. There are four other publication lists the user is subscribed to that are not being returned.

    I made the API call to the List object to confirm the other publication lists are visible. They are returned as follows:
    rrStatus: OK
    rrRequestID: b2e512b6-af6e-443c-b0fb-xxxxxxxxxxxx
    ListName: Partner Promotions
    ListID: 376
    ListName: Feature Updates
    ListID: 377
    ListName: Administrators Only
    ListID: 378
    ListName: Monthly Newsletters
    ListID: 539

    Do you know why this would be happening, have I missed something?
    Thank you in advance for your time.

    Like

  8. For those experiencing similar issues I found the problem.
    There were two issues causing incomplete list data being returned.
    Firstly there were several instances of the same email each with different subscriber keys in Marketing Cloud due to reasons I will not go into here.
    When setting the simple filter I was using the email as the subscriber key. As there were several instances of that email the I was getting back only the lists that all of the instances were subscribed too.
    By changing the filter to use the subscriber key as the subscriber key the required data was returned.

    Like

  9. Ash

    Hi, this article has been a great help! i’ve managed to create a preference centre for the person account using the above, but now i have a requirement to use the same preference centre for the same preferences that exist as leads.
    What would be the most efficient way to do this? would i duplicate the AMPScipt for leads now or is there a shorter way?

    Thanks in advance!

    Like

    1. Hi Ash, no need to copy/rewrite the code.
      I usually add an additional condition in the script, right before the updates in Salesforce are made, to check whether the subscriber coming in is a Lead or a Contact, and then update accordingly:

      /* check if it’s a Lead or a Contact */
      IF Substring(@subscriber_key, 1,3) == “00Q” THEN
      /* Update Lead */
      SET @update_lead = UpdateSingleSalesforceObject(…)
      ELSE
      /* Update Contact */
      SET @update_contact = UpdateSingleSalesforceObject(…)
      ENDIF

      Like

    2. Bhawani

      Hi Ash,

      Have you made the custom preference page for lead and contact? Please can you let me know how we can achieve this? I have also similar functionality but not able to find out where I need to check the lead and contact id?

      Thanks in advance.

      Like

  10. Anna

    Hi Zuzanna! Thank you so much for sharing this code, it was extremely helpful!
    I just wanted to clarify on thing, maybe I adapted to code for person account wrong, but after unsubscribing from all I get to the resubscribe “page” and after I click resubscribe button I see the same page with “resubscribe” and to go to the page with the “go back” button that confirms that changes were appended I need to click on re-subscribe again. So in general I need to click twice. Maybe you would have an idea what can be wrong?

    Like

    1. Anna

      ah, I am sorry, my bad, I missed one part of the code, everything is working perfectly!
      btw, do you hold any knowledge sharing session? 🙂

      Like

  11. Amr Shehata

    Hi Zuzanna,

    Thank you for your blog. Really helpful. I am getting still the ‘ Missing subscriber key” message. I have created a test email, linked the cloud page to that email and sent a preview message to a DE that has an actual subscriber but still getting the same message. Could you please tell what else could it be ? Many thanks

    Like

    1. Hi Amr,
      This error message means that the subscriber key doesn’t get passed from the email to the CloudPage. Without seeing the code in both the email and the CloudPage, it’s really hard to troubleshoot. I would encourage you to take it to Salesforce Stack Exchange (https://salesforce.stackexchange.com/) and paste your code there – the community is usually very fast with resolving AMPscript issues.
      Zuzanna

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s