I'm attempting to add a new Contact into a Salesforce.com account through a CloudPage, but one of the requirements for a new contact is that they are associated to an Account instance. I've not been able to accomplish this, which makes me think it is not possible to insert values into Lookup fields through AMPscript.

Attempts using existing names:

SET @Result = CreateSalesforceObject("Contact", 3, "FirstName", @FirstName, "LastName", @LastName, "Account", "My Account Name") -- Leads to error page, not able to even load

SET @Result = CreateSalesforceObject("Contact", 3, "FirstName", @FirstName, "LastName", @LastName, "Account", "001A0110081BM1") -- Also leads to error page, not able to even load

This is the same for creating or attempting to update. I can do all other limited field types such as picklists without a problem, but no luck with Lookups.

Any help is appreciated!

Field in question

2 Answers 2


I assume by 'insert values into Lookup fields through AMPscript' you are using the AMPscript Lookup() function? For example, you have defined the variables as lookup functions earlier in your code:

var @FirstName, @LastName, @Id, @Result

set @Id = '001A0110081BM1'
set @FirstName = Lookup('Customers','FirstName','Id',@Id)
set @LastName = Lookup('Customers','LastName','Id',@Id)

Either way, this should work. From looking at your code, my guess is that you are using the field name, not the API name, as 'Account' is not a standard API name in the Salesforce Accounts object. Find the API name of the fields that you are using and include them in your CreateSalesforceObject() function.

If you still receive errors, paste your code into an email and preview it using the Send Preview button in the email app. Select any subscriber from the All Subscribers list and when you click Generate Preview debug information will be displayed.

  • Thanks for the response. When I refer to a 'Lookup" field I mean that it is the 'Lookup' data type within Salesforce. Apologies for the confusion. I am 'looking up' Salesforce Data too, but the function is RetrieveSalesforceObjects. For the Salesforce field, I am using the field name, but the field is associated to the Contact object and it is standard field. I will post the image of the Salesforce field as it appears in my instance. Good advice on the email debugging -- it is also telling me that the Account field does not exist :/ Commented Sep 6, 2016 at 22:40
  • I'm guessing that Lookup Data Type fields are not supported by the Salesforce AMPscript functions. I had exactly the same issue when I tried using a Data Type field that is a multi-picklist value. You will probably need to retrieve this field directly using the Salesforce REST API, SSJS and GTL. Refer to this answer which explains how I implemented this. It's a pain, but it works. Commented Sep 7, 2016 at 0:48
  • Interestingly enough I have not had any issues with retrieving or updating Picklist / MultiPicklist values -- just as long as I posted the multipick values back as a semi-colon separated list Commented Sep 7, 2016 at 23:17

It turns out that there is an 'Id' associated to each standard lookup field name.

For example, in my screenshot it only displays 'Account' as the field name for 'Account Name', but it needs to be written as 'AccountId' in the AMPscript function. We would then have to insert the 15-digit ID of that Account, as opposed to the actual Account Name.

Thanks for the help!


You must log in to answer this question.

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