---
schema_version: "1"
id: 1028acefca201f51b3899658dfb73b8f7b294a5a912de5a4c69da5efbeaa1d84
title: CreateSalesforceObject()
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-create-object.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-salesforce/mc-ampscript-reference-salesforce-create-object.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: fbcd726b6ba579b557877517ecec09197486ad94f90c1fcb87b7890eb5fd03a5
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# CreateSalesforceObject()

Creates a record in a Sales Cloud or Service Cloud object and returns the ID of the record created.

**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

```
CreateSalesforceObject(objectName, numFields,
                       fieldName1, fieldValue1,
                       [fieldName2, fieldValue2] ... )
```

The `CreateSalesforceObject()` function has these parameters:

- `objectName` (string): Required. The API name of the Salesforce object to insert the record into.
- `numFields` (string): Required. The number of fields to insert. This number must match the number of name-value pairs that you specify in the function.
- `fieldName1` (string): Required. The name of the field to insert in the object.
- `fieldValue1` (string): Required. The value to insert for the field.

You can optionally upsert additional keys and values (`[fieldName2, fieldValue2, ...]`) by appending each key-value pair to the list of parameters. You can upsert as many keys and values as necessary in this way.

## Usage

To use the function, pass it the name of the object that you want to insert fields into. Next, specify the number of fields to insert. Finally, add the names and values of the records that you want to insert.

### Creating a Record with One Field

This example creates a lead in the integrated Salesforce account with a single field, `EmailAddress`.

```
%%[
  Var @id
  Set @id=CreateSalesforceObject("Lead", 1,
                                 "EmailAddress", "dangelo.cunningham@example.com")
]%%
```

The function returns the ID of the newly created record.

### Creating a Record with Multiple Fields

This example creates a lead with `FirstName`, `LastName`, and `EmailAddress` fields.

```
%%[
  Var @id
  Set @id=CreateSalesforceObject("Lead", 3,
                                 "FirstName", "D'Angelo",
                                 "LastName", "Cunningham",
                                 "EmailAddress", "dangelo.cunningham@example.com")
]%%
```

The function returns the ID of the newly created record.

## See Also

- _Marketing Cloud Engagement Help_: [Marketing Cloud Connect](https://help.salesforce.com/s/articleView?id=mktg.mc_co_marketing_cloud_connect.htm)
