Runtime verified Test scripts included

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).

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

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
]%%

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