[SalesForce] AMPscript – Adding/Updating Salesforce ‘Lookup’ field

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

Best Answer

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.

Related Topic