# data upsert bulk

Bulk upsert records to an org from a CSV file. Uses Bulk API 2.0.

## Description for data upsert bulk

An upsert refers to inserting a record into a Salesforce object if the record doesn't already exist, or updating it if it does exist.

When you execute this command, it starts a job, displays the ID, and then immediately returns control of the terminal to you by default. If you prefer to wait, set the --wait flag to the number of minutes; if it times out, the command outputs the IDs. Use the job and batch IDs to check the status of the job with the "sf data upsert resume" command.

See "Prepare CSV Files" in the Bulk API Developer Guide for details on formatting your CSV file. (<https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_prepare_csv.htm>)

## Flags

| Flag Name (Long)     | Flag Name (Short) | Description                                                                                                                                                  |
| -------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--api-version`      | N/A               | **Type:** Value<br><br>Override the api version used for api requests made by this command                                                                   |
| `--column-delimiter` | N/A               | **Type:** Value<br>**Valid Values:** `BACKQUOTE`, `CARET`, `COMMA`, `PIPE`, `SEMICOLON`, `TAB`<br><br>Column delimiter used in the CSV file.                 |
| `--external-id`      | `-i`              | **Type:** Value<br>**Required**<br><br>Name of the external ID field, or the Id field.                                                                       |
| `--file`             | `-f`              | **Type:** Value<br>**Required**<br><br>CSV file that contains the IDs of the records to update or delete.                                                    |
| `--flags-dir`        | N/A               | **Type:** Value<br><br>Import flag values from a directory.                                                                                                  |
| `--json`             | N/A               | **Type:** Boolean<br><br>Format output as json.                                                                                                              |
| `--line-ending`      | N/A               | **Type:** Value<br>**Valid Values:** `CRLF`, `LF`<br><br>Line ending used in the CSV file. Default value on Windows is `CRLF`; on macOS and Linux it's `LF`. |
| `--sobject`          | `-s`              | **Type:** Value<br>**Required**<br><br>API name of the Salesforce object, either standard or custom, that you want to update or delete records from.         |
| `--target-org`       | `-o`              | **Type:** Value<br>**Required**<br><br>Username or alias of the target org. Not required if the `target-org` configuration variable is already set.          |
| `--wait`             | `-w`              | **Type:** Value<br><br>Number of minutes to wait for the command to complete before displaying the results.                                                  |

## Examples for data upsert bulk

Bulk upsert records to the Contact object in your default org:

```shell
sf data upsert bulk --sobject Contact --file files/contacts.csv --external-id Id
```

Bulk upsert records to a custom object in an org with alias my-scratch and wait 5 minutes for the command to complete:

```shell
sf data upsert bulk --sobject MyObject__c --file files/file.csv --external-id MyField__c --wait 5 --target-org my-scratch
```
