CreateSalesforceObject
Creates a new record in a connected Salesforce Sales or Service Cloud object via Marketing Cloud Connect and returns the 18-character ID of the created record. Runtime-proven on a live Marketing Cloud Engagement CloudPage — including that a successful create returns a real Salesforce ID and a fault aborts the page instead of returning an error value.
Syntax
CreateSalesforceObject(objectName, numFields, fieldName1, fieldValue1[, fieldNameN, fieldValueN, ...]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
objectName |
string | Yes | API name of the Salesforce object to insert into |
numFields |
number | Yes | Number of field name/value pairs that follow; must match the pairs supplied |
fieldName1 |
string | Yes | API name of the first field to set |
fieldValue1 |
string | number | Yes | Value for 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; numFields counts the pairs, not the arguments. There is no upper bound on the number of pairs.
Example
%%[
VAR @id
SET @id = CreateSalesforceObject("Task", 1, "Subject", "Follow up")
]%%
Created: %%=v(@id)=%%
Renders Created: 00T... — the 18-character ID of the new record, whose three-character prefix identifies the object type (00T for a Task).
This function inserts a live record into the connected Salesforce org. AMPscript has no matching delete function, so a record created this way cannot be removed from AMPscript. Only run the success path against data you are willing to keep.
A realistic use passes several fields in one call, keeping numFields in step:
%%[
VAR @id
SET @id = CreateSalesforceObject("Task", 2, "Subject", "Callback", "Status", "Not Started")
]%%
Return value
string — the 18-character Salesforce ID of the newly created record.
There is no closed set of sentinel values: the return is an ID string when the insert succeeds. A fault does not yield a testable error value — see below.
Behaviour
A successful create round-trips to the connected org and returns a real ID. The function issues a SOAP request through Marketing Cloud Connect. Creating a Task with a single field returned an 18-character ID whose 00T prefix marks it as a Task, confirming the record was committed in the org.
The number of pairs is declared, not inferred. numFields states how many field name/value pairs follow. The count must match the pairs actually supplied.
A fault aborts the page
AMPscript has no try/catch, so a fault from the connected org — an object API name that does not exist, or a field name that is not valid on the object — aborts the whole CloudPage with HTTP 422 and discards everything already rendered. There is no error value to test for; the function either returns an ID or aborts.
CreateSalesforceObject("NotARealObject__x", 1, "Subject", "zzz") and a call naming a field that does not exist on the object each aborted the page with HTTP 422. Validate object and field API names before the call rather than relying on a graceful failure.
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: no start marker renders */
IF @b == "badobj" THEN
OutputLine(Concat("badobj start"))
VAR @id1
SET @id1 = CreateSalesforceObject("NotARealObject__x", 1, "Subject", "zzz")
OutputLine(Concat("badobj.id=[", @id1, "]"))
ENDIF
/* an unknown field name on a real object faults and aborts the page */
IF @b == "badfield" THEN
OutputLine(Concat("badfield start"))
VAR @id2
SET @id2 = CreateSalesforceObject("Lead", 1, "NotAFieldName__x", "zzz")
OutputLine(Concat("badfield.id=[", @id2, "]"))
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
UpdateSingleSalesforceObject— update a record in the same connected orgRetrieveSalesforceObjects— read records backLongSFID— convert a 15-character ID for matching- Official reference · ampscript.guide