I've made a preference page in which the form directly communicates with the connected Salesforce environment. I save the customer's data via the UpdateSingleSalesforceObject() function, and I retrieve their data to prefill the form using the RetrieveSalesforceObject() function. I do this to make sure the displayed data is always accurate.

However, the RetrieveSalesforceObject() function causes the page to load very slowly (>8 sec loading time). I tested the page in a couple of online webpage performance meters. The majority of the loading time is classified as 'Wait' time.

This is the code I use for firstName, this block is repeated 8 times each for different attributes (last name, phone number etc.)

SET @firstNameObject = RetrieveSalesforceObjects('Contact', 'FirstName', 'Id', '=', @id)
  IF RowCount(@firstNameObject) > 0 THEN 
    SET @firstNameRow = Row(@firstNameObject, 1)
    SET @firstName = Field(@firstNameRow, "FirstName")

Does anybody know how I can optimize this so the load time is a lot less?

2 Answers 2


There are a couple of things that you can do here.

For an example, you could do just one call per Contact to retrieve all the required fields at once. As RetrieveSalesforceObjects function allows you to grab as many as you need, as long as the attributes are on the same object.

Another option is to grab the attributes from a Synchronised Data Extension instead, this way Cloud Page would be doing a simple lookup to the Data Extension, instead of an API call to Sales Cloud.

The downside of this approach is the fact that it takes 15 minutes to pull updated records, which may lead to a situation where Contact preferences are actually updated, but they will not immediately show up if Contact opens or refreshes the Cloud Page.

  • 1
    Your first suggestion worked great! The load time has been halved, thanks a lot! It's still a bit slower than pulling the data straight from the Synchronized DE's, but the pro of displaying live data is more important than 2 seconds of load time for me.
    – Rutger
    Jan 16, 2019 at 15:53

You should be able to do this all in a single RetrieveSalesforceObjects() call - by returning multiple fields from the call. This should greatly reduce your processing and 'wait' time.

Something like:

SET @SFObject = RetrieveSalesforceObjects('Contact', 'FirstName,LastName,PhoneNumber,etc...', 'Id', '=', @id)

  IF RowCount(@SFObject) > 0 THEN 

    SET @SFRow = Row(@SFObject, 1)
    SET @firstName = Field(@SFRow, "FirstName")
    SET @lastName = Field(@SFRow, "LastName")
    SET @phoneNumber = Field(@SFRow, "PhoneNumber")

  • I used this, as Rain also suggested, and it works great. Thanks for your input!
    – Rutger
    Jan 16, 2019 at 15:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .