---
title: Create a Salesforce connection
description: Create a Salesforce connection in Catalog Explorer using OAuth (U2M or M2M) or Mutual TLS (mTLS) to store credentials for Lakeflow Connect ingestion.
canonical_url: https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-connection
---

# Create a Salesforce connection

Create a Salesforce connection in Catalog Explorer to store authentication credentials for Lakeflow Connect ingestion. Any user with the `USE CONNECTION` privilege on the connection can then create Salesforce ingestion pipelines without needing direct access to the credentials.

Alternatively, admin users can create a connection and a pipeline at the same time in the data ingestion UI. See [Create an ingestion pipeline](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-pipeline.md).

For privilege requirements, see [Connect to managed ingestion sources](https://docs.databricks.com/aws/en/connect/managed-ingestion.md).

## Prerequisites

Salesforce applies usage restrictions to connected apps. The permissions in the following table are required for a successful first-time authentication. If you lack these permissions, Salesforce blocks the connection and requires an admin to install the Databricks connected app.

| Condition                                                                                                                               | Required permission                                                             |
| --------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| [API Access Control](https://help.salesforce.com/s/articleView?id=xcloud.security_api_access_control_all_users.htm\&type=5) is enabled. | `Customize Application` and either `Modify All Data` or `Manage Connected Apps` |
| API Access Control is not enabled.                                                                                                      | `Approve Uninstalled Connected Apps`                                            |

For background, see [Prepare for Connected App Usage Restrictions Change](https://help.salesforce.com/s/articleView?id=005132365\&type=1) in the Salesforce documentation.

## Create a connection

Salesforce connections support three authentication types in Catalog Explorer. Choose the one that fits your organization:

* **OAuth (user-to-machine)**: You sign in to Salesforce interactively to grant Databricks access. See [OAuth authentication](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-connection.md#oauth-authentication).
* **OAuth (machine-to-machine)**: Databricks authenticates with the client ID and client secret of an External Client App that you create in your Salesforce org, using the OAuth client credentials flow. No one signs in interactively. Choose this when you want the connection to authenticate as an app instead of as a signed-in user. See [OAuth machine-to-machine (M2M) authentication](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-connection.md#oauth-m2m-authentication).
* **Mutual TLS (mTLS)**: Databricks and Salesforce exchange and verify client certificates to establish two-way trust, combined with the OAuth client credentials flow. Choose this for API-only users or when your organization requires mTLS. See [Mutual TLS (mTLS) authentication](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-connection.md#mutual-tls-authentication).

### <a id="oauth-authentication" />OAuth authentication

1. In the Databricks workspace, click **Catalog > External data > Connections > Create connection**.

2. On the **Connection basics** page of the **Set up connection** wizard, specify a unique **Connection name**.

3. In the **Connection type** drop-down menu, select **Salesforce**.

4. (Optional) Add a comment.

5. Click **Next**.

6. If you're ingesting from a Salesforce sandbox account, set **Is sandbox** to `true`.

7. Click **Sign in with Salesforce**.

   You're redirected to Salesforce.

8. If you're ingesting from a Salesforce sandbox, click **Use Custom Domain**, provide the sandbox URL, and then click **Continue**.

   ![Use custom domain button](https://docs.databricks.com/aws/en/images/lakeflow-connect/salesforce-sandbox-use-custom-domain.png)

   ![Enter sandbox URL](https://docs.databricks.com/aws/en/images/lakeflow-connect/salesforce-use-custom-domain-sandbox-url.png)

9. Enter your Salesforce credentials and click **Log in**. Databricks recommends logging in as a Salesforce user that's dedicated to Databricks ingestion.

   > [!IMPORTANT]
   >
   > For security purposes, only authenticate if you clicked an OAuth 2.0 link in the Databricks UI.

10. After returning to the ingestion wizard, click **Create connection**.

### <a id="oauth-m2m-authentication" />OAuth machine-to-machine (M2M) authentication

With OAuth M2M, Databricks uses the OAuth client credentials flow to get an access token for an External Client App that you create in your Salesforce org. The connection uses the permissions of the run-as user that you assign to the app. Set up the app in Salesforce, then create the connection in Databricks.

To set up the External Client App in Salesforce, do the following:

1. In Salesforce Setup, go to **External Client App Manager**, click **New External Client App**, enter a name and contact email, and enable OAuth settings for the app.
2. Enter a **Callback URL**. The client credentials flow doesn't use it, so any placeholder works, for example `https://localhost`.
3. Select the **Manage user data via APIs (`api`)** and **Perform requests at any time (`refresh_token`, `offline_access`)** OAuth scopes. Databricks doesn't request scopes in the client credentials flow, so the access token gets the scopes that you configure on the app.
4. Select **Enable Client Credentials Flow**, and then create the app.
5. On the app's **Policies** tab, click **Edit**, and then do the following:
   1. Under **OAuth Policies**, confirm that **Permitted Users** is set to **Admin approved users are pre-authorized**.
   2. Under **App Policies**, move the **Salesforce API Only System Integrations** profile, or another profile that fits your organization, to **Selected Profiles**.
   3. Under **OAuth Flows and External Client App Enhancements**, confirm that **Enable Client Credentials Flow** is selected, and enter the username of the run-as user. The connection uses this user's permissions. Databricks recommends a Salesforce user that's dedicated to Databricks ingestion.
   4. Click **Save**.
6. Copy the app's consumer key and consumer secret from its OAuth settings. You use these as the client ID and client secret in the Databricks setup.
7. Note your org's My Domain URL. The client credentials flow requires it and doesn't support `login.salesforce.com` or `test.salesforce.com`, including for sandbox orgs.

For details, see [Configure the OAuth 2.0 Client Credentials Flow for External Client Apps](https://help.salesforce.com/s/articleView?id=xcloud.configure_client_credentials_flow_for_external_client_apps.htm\&type=5) in the Salesforce documentation.

To create the connection in Databricks, do the following:

1. In the Databricks workspace, click **Catalog > External data > Connections > Create connection**.

2. On the **Connection basics** page of the **Set up connection** wizard, specify a unique **Connection name**.

3. In the **Connection type** drop-down menu, select **Salesforce**.

4. In the **Auth type** drop-down menu, select **OAuth Machine to Machine**.

5. (Optional) Enter a comment.

6. Click **Next**.

7. Enter the following connection details:

   | Field             | Description                                                                                                                                                                                                                                                                      |
   | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
   | **Client ID**     | The consumer key from your Salesforce External Client App.                                                                                                                                                                                                                       |
   | **Client Secret** | The consumer secret from your Salesforce External Client App.                                                                                                                                                                                                                    |
   | **Instance URL**  | The My Domain URL of your Salesforce org, for example `https://MyDomainName.my.salesforce.com`. For a sandbox org, use the sandbox My Domain URL, for example `https://MyDomainName--SandboxName.sandbox.my.salesforce.com`. The URL must use HTTPS and end in `salesforce.com`. |

8. Click **Create connection**.

To create the connection with SQL instead, run [CREATE CONNECTION](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-connection.md). Store the client secret in a secret scope and reference it with the `secret` function:

```sql
CREATE CONNECTION my_salesforce_m2m_connection
TYPE salesforce
OPTIONS (
  client_id '<consumer-key>',
  client_secret secret('<secret-scope>', '<secret-key>'),
  instance_url 'https://MyDomainName.my.salesforce.com'
);
```

Databricks gets a new access token from Salesforce automatically when the current token expires, so you don't need to update the connection.

### <a id="mutual-tls-authentication" />Mutual TLS (mTLS) authentication

With mutual TLS, both Databricks and Salesforce exchange and verify certificates, so each system confirms the other's identity before exchanging any data. Set up the certificate and an External Client App in Salesforce, then create the connection in Databricks.

**Salesforce setup**

1. Ensure that mutual authentication is enabled for your Salesforce account. See [Enable mutual authentication](https://help.salesforce.com/s/articleView?id=000382193\&type=1) in the Salesforce documentation.

2. Generate and upload a certificate authority (CA)-signed certificate in Salesforce:

   1. From **Setup**, in the **Quick Find** box, enter `Certificate and Key Management`, and then select **Certificate and Key Management**.
   2. Select **Create CA-Signed Certificate** and enter the details to generate the certificate signing request (CSR).
   3. Send the CSR to a CA that Salesforce recognizes. For the list of trusted CAs, see the [Salesforce CA list](https://login.salesforce.com/cacerts.jsp).
   4. Get the private key that corresponds to the certificate. You use this key in the Databricks setup.

   For detailed steps, see [Upload a signed certificate](https://help.salesforce.com/s/articleView?id=sf.security_keys_uploading_signed_cert.htm\&type=5) in the Salesforce documentation.

3. Verify that the signed certificate bundle contains the root and intermediate certificates, and that the certificate metadata lists a public CA as the issuer.

4. Combine the client, intermediate, and root certificates into a single file, in the order **Leaf (client)**, **intermediate**, then **root**. Separate each certificate with `BEGIN CERTIFICATE` and `END CERTIFICATE` blocks.

5. Save the private key in a separate file in PEM (`.pem`) format.

6. Create an External Client App in your Salesforce org and configure it for the OAuth client credentials flow, as described in [OAuth machine-to-machine (M2M) authentication](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-connection.md#oauth-m2m-authentication). For the run-as user, enter the user for whom you enabled the mutual authentication profile. For detailed steps, see [Configure the OAuth 2.0 Client Credentials Flow for External Client Apps](https://help.salesforce.com/s/articleView?id=xcloud.configure_client_credentials_flow_for_external_client_apps.htm\&type=5) in the Salesforce documentation.

7. Note the **consumer key** and **consumer secret** for the External Client App. You use these as the client ID and client secret in the Databricks setup.

**Databricks setup**

1. In the Databricks workspace, click **Catalog > External data > Connections > Create connection**.

2. On the **Connection basics** page of the **Set up connection** wizard, specify a unique **Connection name**.

3. In the **Connection type** drop-down menu, select **Salesforce**.

4. In the **Auth type** drop-down menu, select **Mutual TLS**.

5. (Optional) Enter a comment.

6. Click **Next**.

7. Enter the following connection details:

   | Field                  | Description                                                                                                                                         |
   | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
   | **Client ID**          | The consumer key from your Salesforce External Client App.                                                                                          |
   | **Client Secret**      | The consumer secret from your Salesforce External Client App.                                                                                       |
   | **Instance URL**       | The domain URL for your Salesforce account, for example `https://DomainName.my.salesforce.com`. The URL must use HTTPS and end in `salesforce.com`. |
   | **Client Private Key** | The private key in PEM format that corresponds to the certificate you uploaded to Salesforce.                                                       |
   | **Client Certificate** | The certificate chain in PEM format. Enter the same certificate chain that you uploaded to Salesforce.                                              |

8. Click **Create connection**.

## Next steps

[Create an ingestion pipeline](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-pipeline.md).
