Runtime verified Test scripts included

Syntax

UpdateSingleSalesforceObject(objectName, idToUpdate, fieldName1, fieldValue1[, fieldNameN, fieldValueN, ...])  →  number

Parameters

Name Type Required Description
objectName string Yes API name of the Salesforce object to update
idToUpdate string Yes ID of the record to update
fieldName1 string Yes API name of the first field to update
fieldValue1 string | number Yes Value to assign to the first field
fieldNameN string No Further field name
fieldValueN string | number No Value for the corresponding further field

Fields are supplied as repeating name/value pairs; there is no upper bound on the number of pairs.

Example

%%[
  VAR @ok
  SET @ok = UpdateSingleSalesforceObject("Task", @recordId, "Description", "Reviewed")
]%%
Updated: %%=v(@ok)=%%

Renders Updated: 1 — the update succeeded. @recordId is the ID of a record that already exists in the connected org, for example one returned by CreateSalesforceObject or RetrieveSalesforceObjects.

Return value

number1 when the update succeeds.

Per the official reference a failed update returns 0, but on a CloudPage a failure does not surface that value — see below. Because only 1 is observable in this context, there is no closed 0/1 set to test for on a CloudPage.

Behaviour

A successful update round-trips to the connected org and returns 1. The function issues a SOAP request through Marketing Cloud Connect. Updating one field of a record that already exists — an ID returned by CreateSalesforceObject earlier in the same run — returned the literal 1 with the page rendering normally.

A failed update aborts the page instead of returning 0

An unknown object name, a malformed ID, and a well-formed but non-existent Lead ID at both 15 and 18 characters each aborted the page with HTTP 422 rather than returning 0. Confirm the record ID exists before the call rather than relying on a 0 return.

Show test script
%%[
  VAR @b
  SET @b = RequestParameter("b")

  /* control: proves the harness compiles and the page serves 200 */
  IF @b == "alive" THEN
    OutputLine(Concat("CTRL=[alive]"))
  ENDIF

  /* an unknown object name faults and aborts the page */
  IF @b == "badobj" THEN
    OutputLine(Concat("badobj start"))
    VAR @r1
    SET @r1 = UpdateSingleSalesforceObject("NotARealObject__x", "00Q000000000000AAA", "Description", "zzz")
    OutputLine(Concat("badobj.result=[", @r1, "]"))
  ENDIF

  /* a malformed record ID faults and aborts the page */
  IF @b == "noid" THEN
    OutputLine(Concat("noid start"))
    VAR @r2
    SET @r2 = UpdateSingleSalesforceObject("Lead", "00Q000000000000AAA", "Description", "zzz")
    OutputLine(Concat("noid.result=[", @r2, "]"))
  ENDIF

  /* a well-formed but non-existent 18-char Lead ID faults and aborts the page */
  IF @b == "id18" THEN
    OutputLine(Concat("id18 start"))
    VAR @r3
    SET @r3 = UpdateSingleSalesforceObject("Lead", "00Q9V00000ABCDEUA4", "Description", "zzz")
    OutputLine(Concat("id18.result=[", @r3, "]"))
  ENDIF
]%%

Availability

Platform Available
Marketing Cloud Engagement Yes
Marketing Cloud Next No

Requires an active Marketing Cloud Connect integration to a Sales or Service Cloud org on the business unit.

See also