0

Is there a way to do an upsert from a CloudPage to a Salesforce Sales Cloud Object? In this case the need is to update the Account Object.

Scenario: A new subscriber is created in marketing cloud and receives an email (double opt in)

if he/she activates the email with a standard button I can change the data extension in marketing cloud but I also need to update the CRM. How do I do an upsert from here? is it even possible?

1 Answer 1

2

You can use UpdateSingleSalesforceObject function, to update a field on a specific record in Sales Cloud, as per below:

%%[
var @result, @accountid
set @accountid = RequestParameter("AccountID")
set @result = UpdateSingleSalesforceObject('Account',@accountid,'DoubleOptIn','TRUE')
]%%

If you need a solution which can either update or create a record, you will need to use a combination of three functions:

  1. CreateSalesforceObject
  2. RetrieveSalesforceObjects
  3. UpdateSingleSalesforceObject

Which should be combined as follows:

%%[
var @rowset, @numberOfRows, @i, @update, @create, @lastname
set @lastname = RequestParameter("lastname")
set @rowset = RetrieveSalesforceObjects('Contact', 'FirstName, Email', 'LastName', '=', @lastname)
if not empty(@rowset) then
set @numberOfRows = RowCount(@rowset)
for @i = 1 to @numberOfRows do
set @update = UpdateSingleSalesforceObject('Contact',Field(@row, "Id"),'DoubleOptIn','TRUE')
next @i
ELSE
  set @create = CreateSalesforceObject(
        "Contact", 4,
        "FirstName", RequestParameter("firstname"),
        "LastName", RequestParameter("lastname"),
        "DoubleOptIn", 'TRUE',
        "Email", RequestParameter("email")
       )
ENDIDF
]%%
2
  • Hey Lukas, thanks for your answer. Does this function also create a new record in case it is not present in the Sales Cloud Object?
    – Yattaman
    Commented Jun 11, 2020 at 7:46
  • @Yattaman - I have updated my answer accordingly. You will need some more code to achieve that Commented Jun 11, 2020 at 8:27

You must log in to answer this question.

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