---
schema_version: "1"
id: 218e99a936bfe58375734aaec9c5387e89bbe53c3e67345d338e0b8af73f6401
title: UpdateSingleSalesforceObject()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/salesforce/mc-ampscript-reference-salesforce-update-single-object.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-salesforce/mc-ampscript-reference-salesforce-update-single-object.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: aecd122093fde315a1c64a4203d6ed81ee93299946563bc09cd138c884efe273
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# UpdateSingleSalesforceObject()

Updates a record in a Salesforce object.

**important:** To use this function, you must use [Marketing Cloud Connect](https://help.salesforce.com/s/articleView?id=mktg.mc_co_marketing_cloud_connect.htm) to integrate with Sales Cloud or Service Cloud.

When you call this function, it issues a SOAP request to your Salesforce org. SOAP API requests aren’t subject to the API usage limits that apply to your org.

For best performance, we recommend that you minimize the use of this function in sends. Using this function in large sends can result in the sends failing to complete.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>❌ No</td>
  </tr>
</table>

## Syntax

```
UpdateSingleSalesforceObject(objectName, idToUpdate, fieldName, fieldValue)
```

The `UpdateSingleSalesforceObject()` function has four parameters:

- `objectName` (string): Required. The API name of the Salesforce object to update.
- `idToUpdate` (string): Required. The ID of the record to update.
- `fieldName` (string): Required. The name of the field to update.
- `fieldValue` (string): Required. The value to assign to the named field.

## Usage

This example updates the Email field on the Lead with ID 00Q00003yAEj to contain pooja.chatterjee@example.com. If the function successfully updates the specified record, it returns `1`; otherwise, it returns `0`.

```
%%[
  Var @result, @sfObject, @id, @fieldName, @fieldValue
  Set @sfObject = "Lead"
  Set @id = "00Q00003yAEj"
  Set @fieldName = "Email"
  Set @fieldValue = "pooja.chatterjee@example.com"

  Set @result = UpdateSingleSalesforceObject(@sfObject, @id, @fieldName, @fieldValue)
  If @result == 1 then
]%%

<p>Record with ID %%=v(@id)=%% updated successfully.</p>

%%[ else ]%%

<p>Record with ID %%=v(@id)=%% was not updated.</p>

%%[ EndIf ]%%
```

The example outputs a message that tells you whether it successfully updated the record.

## Previewing Content that uses this Function

When you preview code in a webpage or message that uses this function, the function performs an update as it was triggered during a send. To prevent previews from updating live data, use the `_messagecontext` system variable to stop the content from being loaded in the preview context.

```
%%[ If _messagecontext != "PREVIEW" then ]%%

<!-- Add your UpdateSingleSalesforceObject() function call here. -->

%%[ EndIf ]%%
```
