I need to personalize a triggered send using Marketing Cloud Connect and a custom object to contact relationship, but I'm not getting results for the relationship. My AMPscript looks like this:

Set @mySObject = AttributeValue("SObject")
Set @myRecordId = AttributeValue("RecordId")

Set @customObject = RetrieveSalesforceObjects(@mySObject,"Field__c, Contact__r.Name","Id", "=",@myRecordId)

var @customObjectRow, @fieldValue, @contactName
Set @customObjectRow = Row(@customObject, 1)
Set @fieldValue = FIELD(@customObjectRow, "Field__c")
Set @contactName = FIELD(@customObjectRow, "Contact__r.Name")

This will have a value: %%=v(@fieldValue)=%%
This will have a blank value: %%=v(@contactName)=%%

I've been reading documentation all night and haven't found anything useful. Can you use object relationships straight from Sales Cloud without having to do another RetrieveSalesforceObjects function call?

1 Answer 1


You are using Contact__r.Name which isn't a proper AMPscript syntax. What you need to do, is declare api names of all fields that you want to retrieve from the object, for example:

set @subscriberRows = RetrieveSalesforceObjects(
   "Id", "=", _subscriberKey )
  • "Contact" is the object from which you are retrieving
  • "FirstName,LastName,Email" are the fields you are retrieving
  • "Id", "=", _subscriberKey is how you match your Salesforce Data with Marketing Cloud data

Read more here: https://ampscript.guide/retrievesalesforceobjects/

  • So the solution here is to make 2 RetrieveSalesforceObjects function calls ... one to retrieve data from the custom object and one to retrieve data from the related contact? I've been reading the Ampscript guide book, but I can't find anything about retrieving data from related objects through lookups, which is really my issue. Aug 16, 2019 at 11:43
  • retrieving data from related objects through lookups > that won't work in Marketing Cloud, al least not the way it works in Sales Cloud. If you have the field from custom object included in your Contact as a lookup, you can retrieve it but it will show up as the Object ID of that related object. Try it and see what results you get: set @subscriberRows = RetrieveSalesforceObjects("Contact","LookupField__c","Id", "=", @myRecordId)
    – zuzannamj
    Aug 16, 2019 at 12:17
  • and yes, if just the Id of that related object isn't enough, you will have to make a second RetrieveSalesforceObjects function call
    – zuzannamj
    Aug 16, 2019 at 12:27
  • @justinpdove if my answer helped, please mark it as accepted - thanks!
    – zuzannamj
    Aug 16, 2019 at 13:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .