Runtime verified Test scripts included

Syntax

RetrieveSalesforceJobSources(jobId)  →  rowset

Parameters

Name Type Required Description
jobId number Yes The numeric job ID of the Salesforce-triggered send to retrieve the audience sources of

Example

%%[
  VAR @rows, @count
  SET @rows = RetrieveSalesforceJobSources(999999999)
  SET @count = RowCount(@rows)
]%%
Sources: %%=v(@count)=%%

Renders Sources: 0 for a job ID with no matching sources — an unmatched lookup yields an empty rowset rather than an error.

Once a rowset comes back, walk it with RowCount, Row and Field:

%%[
  VAR @rows, @i, @row
  SET @rows = RetrieveSalesforceJobSources(40029164)
  FOR @i = 1 TO RowCount(@rows) DO
    SET @row = Row(@rows, @i)
    Output(Concat(
      "SourceID=", Field(@row, "SourceID"),
      " SourceType=", Field(@row, "SourceType"),
      " IsInclusionSource=", Field(@row, "IsInclusionSource"), "<br>"))
  NEXT @i
]%%

Return value

rowset — one row per audience source of the referenced send, with the fields SourceID, SourceType and IsInclusionSource, each addressable through Field(Row(@rows, n), "FieldName").

There is no closed set of sentinel values: the result is a rowset whose size depends on the job. A job ID with no matching sources returns an empty rowset (RowCount of 0, Empty of true).

The function reports nothing about the status of the job itself — it returns source data even for a cancelled job, so do not use it to test whether a send completed.

Behaviour

A live lookup round-trips to the connected org. The function issues a request through Marketing Cloud Connect. RetrieveSalesforceJobSources(999999999) and RetrieveSalesforceJobSources(0) each returned a valid AMPscript rowset with the page rendering normally.

An unmatched job ID is a rowset, not an error. A job ID with no matching sources returns a rowset whose RowCount is 0 and whose Empty is true — it does not abort the page or return an error value.

Show test script
%%[
  /* a job ID with no matching sources returns an empty rowset, not an error */
  VAR @rows, @rc
  SET @rows = RetrieveSalesforceJobSources(999999999)
  SET @rc = RowCount(@rows)
  OutputLine(Concat("rowcount=[", @rc, "] isEmpty=[", Empty(@rows), "]"))

  /* iterate the sources of a real Salesforce send by its numeric job ID */
  VAR @jobRows, @jobCount, @i, @row
  SET @jobRows = RetrieveSalesforceJobSources(40029164)
  SET @jobCount = RowCount(@jobRows)
  IF @jobCount > 0 THEN
    FOR @i = 1 TO @jobCount DO
      SET @row = Row(@jobRows, @i)
      OutputLine(Concat(
        "SourceID=", Field(@row, "SourceID"),
        " SourceType=", Field(@row, "SourceType"),
        " IsInclusionSource=", Field(@row, "IsInclusionSource")))
    NEXT @i
  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