UpdateSingleSalesforceObject()

Updates a record in a Salesforce object.

To use this function, you must use Marketing Cloud Connect to integrate with Sales Cloud or Service Cloud.

Important

When you call this function, it issues a SOAP request to your Salesforce org. SOAP API requests aren’t subject to the API usage limits that apply to your org.

For best performance, we recommend that you minimize the use of this function in sends. Using this function in large sends can result in the sends failing to complete.

Availability 

Marketing Cloud Engagement ✅ Yes
Marketing Cloud Next ❌ No

Syntax 

1UpdateSingleSalesforceObject(objectName, idToUpdate, fieldName, fieldValue)

The UpdateSingleSalesforceObject() function has four parameters:

  • objectName (string): Required. The API name of the Salesforce object to update.
  • idToUpdate (string): Required. The ID of the record to update.
  • fieldName (string): Required. The name of the field to update.
  • fieldValue (string): Required. The value to assign to the named field.

Usage 

This example updates the Email field on the Lead with ID 00Q00003yAEj to contain pooja.chatterjee@example.com. If the function successfully updates the specified record, it returns 1; otherwise, it returns 0.

1%%[
2  Var @result, @sfObject, @id, @fieldName, @fieldValue
3  Set @sfObject = "Lead"
4  Set @id = "00Q00003yAEj"
5  Set @fieldName = "Email"
6  Set @fieldValue = "pooja.chatterjee@example.com"
7
8  Set @result = UpdateSingleSalesforceObject(@sfObject, @id, @fieldName, @fieldValue)
9  If @result == 1 then
10]%%
11
12<p>Record with ID %%=v(@id)=%% updated successfully.</p>
13
14%%[ else ]%%
15
16<p>Record with ID %%=v(@id)=%% was not updated.</p>
17
18%%[ EndIf ]%%

The example outputs a message that tells you whether it successfully updated the record.

Previewing Content that uses this Function 

When you preview code in a webpage or message that uses this function, the function performs an update as it was triggered during a send. To prevent previews from updating live data, use the _messagecontext system variable to stop the content from being loaded in the preview context.

1%%[ If _messagecontext != "PREVIEW" then ]%%
2
3<!-- Add your UpdateSingleSalesforceObject() function call here. -->
4
5%%[ EndIf ]%%