Cloud Page
Marketing Cloud

Use Cloud pages to retrieve and update Salesforce CRM data real-time

Use Case:

Client wanted to use a custom profile/preference centre page wherein the source of data is Salesforce i.e. they have CRM connected with SFMC and ContactID is used as the Subscriber key. The idea behind using CRM as the source of data is to always display the most updated information to the client on the profile page and any updates done by subscribers gets updated in the source system Salesforce CRM. The solution below outlines the core concept of retrieving and updating CRM data through cloud page so it can be used on any similar situation.


  • Should have Salesforce CRM Enterprise or above edition.
  • Salesforce CRM should be integrated to SFMC using Marketing Cloud Connect.


In this solution, we use AmpScript functions to retrieve and update the Salesforce CRM contact records. There is no HTML and CSS on this solution overview so you can add yours as needed.

The following steps to retrieve the Salesforce CRM profile data on the cloud page.

  1. Create a landing CloudPage under Web Studio.


  2. There are two ways to get a Contact ID on the cloud page when a user clicks on an Update Profile hyperlink through the email message:
    • Pass parameters with the Cloud page URL such as “ContactID”. The cloud page uses “ContactID” in the request parameter.
      Set @subkey = RequestParameter(“ContactID”)
    • Without passing any parameter with the Cloud page URL and using the Subscriber key if we know that is the ‘ContactID’.
      Set @subkey = _subscriberkey
  3. Retrieve subscriber details from the Salesforce CRM Contact object, where the subscriber key is equal to the ‘Contact ID’.
    Set @subkey = _subscriberkey
    SET @ conSubsRows = RetrieveSalesforceObjects("Contact", "FirstName, LastName, Email, MobilePhone", "Id", "=", @subkey )

    In the code above, I am retrieving First Name, Last Name, Email and Mobile phone from the contact record. You can add/remove fields as needed, use the API name of the fields from SD CRM in order to retrieve them.

  4. If a subscriber’s Contact ID is found in the Salesforce Contact record, then the cloud page displays the retrieved values in the form else displays the error message “No subscriber found”.
    If Substring(@subkey,1,3) == "003" then
    // Retrieve and Update Code
    SET @nsubflag = true
    SET @nosubMsg = "Subscriber not found"



  5. Update the retrieved profile values like FirstName, Email, Mobile Number, etc. on the CloudPage and then submit to get stored and update the Salesforce Contact record.
  6. Make sure to set some variables to store data on the cloud page and use these variables to map with CRM field values.
    SET @ updateContactRecord = UpdateSingleSalesforceObject("Contact", @subkey,"FirstName", @firstNameVal,"LastName", @lastNameVal,"MobilePhone", @mobileVal)
  7. Once the values are updated on the contact record then the page will redirect to the Thank You page.


Let’s see the AmpScript code to get and update the contact record with the complete code block.
Below I have pasted the entire code for the approach that you can use and modify as needed.

SET @subkey = _subscriberkey  /* "Using system attribute to get Subscriber Key (003DI00000XXXXXXXX)" */
IF Substring(@subkey,1,3) == "003" THEN /* "Checking Subscriber Key(ContactID) starts from 003" */
SET @conSubsRows = RetrieveSalesforceObjects("Contact","FirstName,LastName,Email,MobilePhone","Id", "=", @subkey ) /* "Retrieve Contact record from the Salesforce CRM where ContactID is equals to the subscriber key" */
IF RowCount(@conSubsRows) == 1 THEN /* Count retrieving rows, there should only be one row */
VAR @conSubsRow, @firstName, @lastName, @emailAddress, @mobile
SET @conSubsRow = Row(@conSubsRows, 1)
/* Map retrieved values to the variables and use to display dynamic values in the form */
SET @firstName = Field(@conSubsRow, "FirstName")
SET @lastName = Field(@conSubsRow, "LastName")
SET @emailAddress = Field(@conSubsRow, "Email")
SET @mobile = Field(@conSubsRow, "MobilePhone")
IF RequestParameter('submitBtn') == "SUBMIT" THEN /* Getting submit request on click Submit Button*/
SET @firstNameVal =  RequestParameter("Firstname") /* Map updated values on Submit */
SET @lastNameVal =  RequestParameter("Lastname")
SET @mobileVal =  RequestParameter("Mobile")
SET @emailVal = RequestParameter("subEmail")
/* Update Salesforce Contact record */
SET @updateContactRecord = UpdateSingleSalesforceObject("Contact", @subkey,"FirstName", @firstNameVal,"LastName", @lastNameVal,"MobilePhone", @mobileVal)
IF @updateContactRecord > 0 THEN   /* If contact record is updated then redirect to the Thank you Page*/
Redirect(concat("", @subkey))
ELSE /* If ContactID didn’t match with the Salesforce Contact record */
SET @nosubflag = true
SET @nosubMsg = "Subscriber not found"


  1. Here we are retrieving profile data from the Salesforce Contact Object, similarly, we can do this for the Lead object or both of them together.
  2. The form fields are set with real-time dynamic values retrieved from Salesforce CRM Contact records.

Hope this helps, please do share and comment.

Leave a Reply