How can i retreive a related object with ampscript? I read the whole forum and looked it up in Google but i can't get it to work.

I tried this but it returns the error: An unrecognized expression appears in a script block.

    Var @field
    Set @field = Placement__c_Salesforce:Vessel_Rig_Platform__r:name



1 Answer 1


You have to use the RetreiveSalesforceObjects Ampscript call and parse it with the Rows call.

Assuming you are searching the lead object (If its a custom object, change the value accoridngly)

Set @rs= RetrieveSalesforceObjects('Lead', 'Placement__c_Salesforce', 'Vessel_Rig_Platform__r', '=', @QueryValue)

IF NOT Empty(@rs) THEN 
    Set @row = ROW(@rs,1)
    Set @QueryValue = FIELD(@row,"Placement_c_Salesforce")

  • 1
    Thanks for your reply Data_Kid, i am quite new to AMPscript and eager to learn. Can you please provide the AMPscript?
    – eazy4me
    Feb 8, 2018 at 12:18
  • I have provided a code snippet and a link to the documentation to assit @wfrankhuizen
    – 0xsegfault
    Feb 8, 2018 at 12:26
  • Sorry but the code isn't working. I need the Placement__c_Salesforce:Vessel_Rig_Platform__r:name and in your code i doesn't refer to that.
    – eazy4me
    Feb 8, 2018 at 15:23
  • please refrain from asking for working (copy pasteable) code samples, instead, go through the documenttion, do trailhead(s), and keep trying. Open new posts with specific problems related to your code instead of opening How To questions. Thanks!
    – glls
    Feb 8, 2018 at 20:08
  • I did all the trailheads and read all documentation about the functions. Because i am a complete beginner i need to understand how i can return related objects with RetreiveSalesforceObjects. I can't find it anywhere and did a few hours of testing already.
    – eazy4me
    Feb 9, 2018 at 7:08

You must log in to answer this question.

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