UpdateSingleSalesforceObject

This function updates a record in a Sales or Service Cloud standard or custom object. The function returns 1 if the record is updated successfully or 0if it fails.

Arguments

UpdateSingleSalesforceObject(1,2,3,4,[5a,5b]...)

Ordinal Type Required Description
1 String True API name of the Salesforce object
2 String True Record identifier to update
3 String True API field name to update
4 String True Value to update
5a String False Additional API field name to update (see note)
5b String False Additional value to update (see note)

NOTE: Additional API field name and value pairs can be appended as arguments.

NOTE: Certain Salesforce objects enforce record-locking when a record is modified, to ensure the referential integrity of data. This applies to records that have a relationship to lookup records in a different object. If the function is used to asynchronously update multiple records (for example, the function is included in an email) and the object has lock contention, the records may fail to update.

TIP: If the field value to update is empty, the existing field value will remain unchanged on the Salesforce record object. However, you can include a fieldsToNull property as a function argument to reset a single field value to null, as per the second example below.

Example 1

The following example pre-populates a landing page form with a Contact record using the RetrieveSalesforceObjects function.

When the form is submitted, the UpdateSingleSalesforceObject function updates the Contact record with values from the submitted form.

%%[

var @Id, @firstName, @lastName, @email, @subscriberRows, @subscriberRow
set @Id = _subscriberKey

if RequestParameter("submitted") != true then

  set @subscriberRows = RetrieveSalesforceObjects(
     "Contact",
     "FirstName,LastName,Email",
     "Id", "=", @Id )

  set @subscriberRow = Row(@subscriberRows, 1)
  set @firstName = Field(@subscriberRow, "FirstName")
  set @lastName = Field(@subscriberRow, "LastName")
  set @email = Field(@subscriberRow, "Email")

else

  var @updateRecord
  set @firstname = RequestParameter("firstname")
  set @lastName = RequestParameter("lastname")
  set @email = RequestParameter("email")
  set @updateRecord = UpdateSingleSalesforceObject(
      "Contact", @Id,
      "FirstName", @firstname,
      "LastName", @lastName,
      "Email", @email
     )

endif

]%%
<!DOCTYPE html>
<html>
   <body>
      %%[ if @updateRecord == 1 then ]%%
         <p>Record Updated</p>
      %%[ elseif @updateRecord == 0 then ]%%
        <p>Update Failed</p>
      %%[ endif ]%%
      <h2>Update Your Details</h2>
      <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
         <label>First name</label>
         <input type="text" name="firstname" value="%%=v(@firstName)=%%">
         <label>Last name</label>
         <input type="text" name="lastname" value="%%=v(@lastName)=%%">
         <label>Email</label>
         <input type="text" name="email" value="%%=v(@email)=%%">
         <input name="submitted" type="hidden" value="true" />
         <input type="submit" value="Submit">
      </form>
   </body>
</html>

Output

If the record is updated successfully, a confirmation message will be displayed and the form fields will be populated with the submitted form values.

<!DOCTYPE html>
<html>
   <body>
      <p>Record Updated</p>
      <h2>Update Your Details</h2>
      <form action="https://pub.exacttarget.com/lcuh4w3abcd?qs=1550dccf35ce..." method="post">
         <label>First name</label>
         <input type="text" name="firstname" value="Suzy">
         <label>Last name</label>
         <input type="text" name="lastname" value="Jackson">
         <label>Email</label>
         <input type="text" name="email" value="suzy@limedash.com">
         <input name="submitted" type="hidden" value="true" />
         <input type="submit" value="Submit">
      </form>
   </body>
</html>

Example 2


Not a subscriber? Subscribe now.