UpdateSingleSalesforceObject
Updates a single record in a connected Salesforce Sales or Service Cloud object via Marketing Cloud Connect and returns 1 on success. Runtime-proven on a live Marketing Cloud Engagement CloudPage — including that a successful update returns 1 and that a failed update aborts the page instead of returning the documented 0.
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.
This function changes a live record in the connected Salesforce org. AMPscript has no delete or reliable revert, so an update made this way cannot be undone from AMPscript. Only run the success path against data you are willing to change.
Return value
number — 1 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
AMPscript has no try/catch, so a fault from the connected org — an unknown object, a malformed ID, or a well-formed but non-existent record ID — aborts the whole CloudPage with HTTP 422 and discards everything already rendered. The documented failure return of 0 never materialises to be read in this context; the update either returns 1 or aborts.
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
]%%
OutputLine given a bare string literal renders an empty line. Wrap the argument in Concat() or your start and done markers vanish silently — which looks exactly like the function failing.
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
CreateSalesforceObject— insert a record into the same connected orgRetrieveSalesforceObjects— read records backLongSFID— convert a 15-character ID for matching- Official reference · ampscript.guide