I have a AmpScript to create a Salesforce Object, which does not work. I want to create a new Lead record. Important is, that I have to create the Record Type: Tenant. In the Salecloud I can choose it by a drop down.

Must have fields are only: Status and Last Name.

But why does this not work:

enter  %%[var @email, @gender, @language, @channel, @status, @record
set @email = "sebhansen83@gmail.com"
set @lastName = "star"
set @gender = "Male"
set @language = "German"
set @channel = "Optin"
set @status = "Open"
set @record = "Tenant"
set @result = CreateSalesforceObject( "Lead", 3, "RecordType", "Tenant", "LastName", @lastName, "Status", @status)]%% 

In Salesforce Record Type is a Lookup field, which physically is stored under RecordTypeId field and it accepts salesforce ID as its value.

So to make it work, you need to push Salesforce ID of that record type than its name.

Proper code will look like:

CreateSalesforceObject( "Lead", 3, "RecordTypeId", "5003000000D8cuI", "LastName", @lastName, "Status", @status)

It's an example ID, it won't work when you just copy&pase this code.

The id of mentioned by you record type you can be obtained or by using SOQL in Developer Console (i.e. SELECT Id, Name FROM RecordType WHERE SobjectType = 'Lead') or on Admin Panel, under Lead > Record Types tab, looking on URL and finding an ID there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.