# Salesforce bulk operation

You can use the Salesforce bulk operation step to perform bulk mutative operations (insert, update, upsert, and delete) on Salesforce objects using the Salesforce Bulk API 2.0.

The step reads data from the stream, buffers a CSV file of mutations, executes the bulk job, and (optionally) returns:

* successful results
* unprocessed records
* failed results

### Before you begin

You must have a Salesforce **Client ID** and **Client secret** to use this step.

### General

* **Step name**: Specify the unique name of the Salesforce bulk operation step on the canvas. You can customize the name or leave it as the default.

### Connection tab

Use this tab to provide Salesforce credentials. The **Client id** and **Client secret** authenticate the service account, and **Username** and **Password** identify the user that the service account impersonates.

![Salesforce bulk operation Connection tab](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-7f4b13b3a9cc9c9383ef49deb7911265ddd83388%2FPDI%20Salesforce%20bulk%20operation%20step%20Connection%20tab.png?alt=media)

| Field                     | Description                                                                 |
| ------------------------- | --------------------------------------------------------------------------- |
| **OAuth2 login endpoint** | Endpoint used to retrieve a token from Salesforce.                          |
| **Client id**             | Client identifier required for the OAuth endpoint.                          |
| **Client secret**         | Client secret required for the OAuth endpoint.                              |
| **Username**              | User name used to authenticate to Salesforce.                               |
| **Password**              | Password for the user.                                                      |
| **Test connection**       | Verifies that the connection can be made to the Salesforce web service URL. |

### Operation tab

Use this tab to define the bulk operation.

![Salesforce bulk operation Operation tab](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-267fbe24163c4cc38c607a4b9eb2978deedd5a06%2FPDI%20Salesforce%20bulk%20operation%20step%20Operation%20tab.png?alt=media)

| Field                          | Description                                                                                                                                                                                    |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Salesforce object type**     | Target Salesforce object type.                                                                                                                                                                 |
| **Bulk operation**             | Operation type: Insert, Update, Upsert, or Delete. Some selections show additional fields.                                                                                                     |
| **Salesforce id stream field** | Available for **Update** and **Delete**. Select an incoming field that contains the Salesforce ID of the object to update or delete.                                                           |
| **External id stream field**   | Available for **Upsert**. Select an incoming field that contains an external (indexed) ID. If the external ID exists in Salesforce, the record is updated; otherwise, a new record is created. |
| **External id object field**   | Available for **Upsert**. Salesforce object field that contains the external ID to match for upserts.                                                                                          |

### Fields tab

Use this tab to define which fields to write for Insert, Update, and Upsert operations. This tab is not available for bulk delete operations.

{% hint style="info" %}
You cannot include the external ID as a mapped field for upsert operations.
{% endhint %}

All incoming values (except dates) are converted to strings using the format masks of the **Stream field**.

![Salesforce bulk operation Fields tab](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-46544d357e41a1002d4bf4e441b3f3ff809ab976%2FPDI%20Salesforce%20bulk%20operation%20step%20Fields%20tab.png?alt=media)

| Field            | Description                                                                                                                                          |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Stream field** | PDI stream field containing the value to write.                                                                                                      |
| **Object field** | Destination Salesforce object field.                                                                                                                 |
| **Clear nulls?** | Select **Yes** to clear values in Salesforce when the incoming value is null. Select **No** (default) to leave existing Salesforce values unchanged. |

### Advanced tab

Use this tab to configure buffer files and API version.

![Salesforce bulk operation Advanced tab](https://773338310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYwnJ6Fexn4LZwKRHghPK%2Fuploads%2Fgit-blob-df095ac1e8047d1084ae6ddc2c71f66db9516723%2FPDI%20Salesforce%20bulk%20operation%20step%20Advanced%20tab.png?alt=media)

| Field                                                  | Description                                                                                                                                       |
| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Path to buffer the bulk job payloads**               | Directory used to store temporary payload files and retrieve output records. Temporary files are deleted when the step finishes.                  |
| **Maximum size of a buffered payload file (in bytes)** | Maximum bytes to buffer/transmit per bulk job payload. Default and maximum is 100 MB (`104857600`). Lower this if needed to avoid locking errors. |
| **Buffer payload only (do not upload in job)**         | Buffers payload files in the specified directory but does not upload them to Salesforce.                                                          |
| **Cleanup bulk jobs once processed**                   | Select to delete buffer files when the step finishes.                                                                                             |
| **Salesforce API version**                             | Salesforce Bulk API version to use.                                                                                                               |

{% hint style="info" %}
Sample transformations are available in `/design-tools/data-integration/plugins/pdi-salesforce-bulk-plugin/samples`:

* `Input SFBL.ktr`
* `Delete SFBL.ktr`
* `Update SFBL.ktr`
* `Upsert SFBL.ktr`
  {% endhint %}

### Metadata injection support

All fields of this step support metadata injection. You can use this step with [ETL metadata injection](https://docs.pentaho.com/pdia-data-integration/pdi-transformation-steps-reference-overview/etl-metadata-injection) to pass metadata to your transformation at runtime.
