The RetrieveSingleSalesforceObjects function returns a rowset from an object in Salesforce (both standard and custom objects). You need to have the connector enabled and configured correctly in order for this AMPscript function to work. You do not need to have the object synced via Synchronized Data Extensions. But you do need to use Row function and Field function in conjunction to extract the data and use them in AMPscript variables.
RetrieveSalesforceObjects(1,2,3,4,5) 1 = Salesforce Object: Account, Contact, Lead, Opportunity (or custom object) 2 = Name of fields to retrieve (comma separated if more than one field) 3 = Field name to use in WHERE clause (only one field) 4 = Operator (=, >, <, !=, <=, >=) to compare field in (3) to value in (5) 5 = Value use to evaluate
%%[ set @rs = RetrieveSalesforceObjects(‘Account’, ‘FirstName, LastName’, ‘PersonContactId’, ‘=’, @subscriberKey) set @rc = rowcount(@rs) IF @rc > 0 THEN SET @row = ROW(@rs,1) SET @FirstName = FIELD(@row,”FirstName”) SET @LastName = FIELD(@row,”LastName”) ENDIF ]%% Hi @FirstName @LastName!
Hi John Doe!
RetrieveSalesforceObjects function is used to retrieve data from Sales or Service Cloud. The
@rs variable to used in the retrieve function and pulling from the
Account object. The fields we want to retrieve from
Account are the
In order to find the correct records on the
Account object, in the
RetrieveSalesforceObjects function, we are using the
PersonContactId. In this example, this is a Person Account. Using the
@subscriberkey and having the
PersonContactId equal that value will allow us to retrieve the correct record on the
Field functions need to be used with the
RetrieveSalesforceObjects function. First we are checking if the retrieve function has and rows retrieved. Using
RowCount, the AMPscript is setting the
@rc variable to check how many rows RetrieveSalesforceObjects function retrieves.
Then using an If function, if the number of rows retrieved is greater than zero then the AMPscript uses the Row function to return the rowset. The Field function then returns the specified field in that row. In this case, it is the
FirstName and the
RetrieveSalesforceObjects function finds the record on the
Account object and retrieves the
FirstName of “John” and the
LastName of “Doe.”