---
title: Run federated queries on Salesforce Data 360
description: Learn how to configure Databricks Lakehouse Federation to run federated queries on Salesforce Data 360 data that is not managed by Databricks.
canonical_url: https://docs.databricks.com/aws/en/query-federation/salesforce-data-cloud
---

# Run federated queries on Salesforce Data 360

This page describes how to set up Lakehouse Federation to run federated queries on Salesforce Data 360 data that is not managed by Databricks. To learn more about Lakehouse Federation, see [Connect to external databases and catalogs](https://docs.databricks.com/aws/en/query-federation/index.md)

To connect to your Salesforce Data 360 database using Lakehouse Federation, you must create the following in your Databricks Unity Catalog metastore (workspaces created after November 8, 2023 already have a Unity Catalog metastore provisioned automatically):

* A *connection* to your Salesforce Data 360 database.
* A *foreign catalog* that mirrors your Salesforce Data 360 database in Unity Catalog so that you can use Unity Catalog query syntax and data governance tools to manage Databricks user access to the database.

### Which Salesforce connector should I use?

Databricks offers multiple connectors for Salesforce. There are two zero-copy connectors: the Salesforce Data 360 (formerly Data Cloud) file sharing connector and the Salesforce Data 360 query federation connector. These allow you to query data in Salesforce Data 360 without moving it. There is also a Salesforce ingestion connector that copies data from various Salesforce products, including Salesforce Data 360 and Salesforce Sales Cloud.

The following table summarizes the differences between the Salesforce connectors in Databricks:

| Connector                            | Use case                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Supported Salesforce products                                                                                                                                                          |
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Salesforce Data 360 file sharing     | When you use the Salesforce Data 360 file sharing connector in Lakehouse Federation, Databricks calls Salesforce Data-as-a-Service (DaaS) APIs to read data in the underlying cloud object storage location directly. Queries are run on Databricks compute without using the JDBC protocol.<br />Compared to query federation, file sharing is ideal for federating a large amount of data. It offers improved performance for reading files from multiple data sources and better pushdown capabilities. See [Lakehouse Federation for Salesforce Data 360 File Sharing](https://docs.databricks.com/aws/en/query-federation/salesforce-data-cloud-file-sharing.md). | Salesforce Data 360                                                                                                                                                                    |
| Salesforce Data 360 query federation | When you use the Salesforce Data 360 query federation connector in Lakehouse Federation, Databricks uses JDBC to connect to source data and pushes queries down into Salesforce. See [Run federated queries on Salesforce Data 360](https://docs.databricks.com/aws/en/query-federation/salesforce-data-cloud.md).                                                                                                                                                                                                                                                                                                                                                     | Salesforce Data 360                                                                                                                                                                    |
| Salesforce ingestion                 | The Salesforce ingestion connector in Lakeflow Connect allows you to create fully-managed ingestion pipelines from Salesforce Platform data. This connector maximizes value by leveraging not only CDP data but also CRM data in the Data + AI Platform. See [Ingest data from Salesforce](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-pipeline.md).                                                                                                                                                                                                                                                                                      | See [Which Salesforce products does the Salesforce ingestion connector support?](https://docs.databricks.com/aws/en/ingestion/lakeflow-connect/salesforce-faq.md#sfdc-product-support) |

## Requirements

Workspace requirements:

* Workspace enabled for Unity Catalog. Workspaces created after November 8, 2023 are enabled for Unity Catalog automatically, including automatic metastore provisioning. You don't need to create a metastore manually unless your workspace predates automatic enablement and hasn't been enabled for Unity Catalog. See [Get started with Unity Catalog](https://docs.databricks.com/aws/en/data-governance/unity-catalog/get-started.md).

Compute requirements:

* Network connectivity from your compute resource to the target database systems. See [Networking recommendations for Lakehouse Federation](https://docs.databricks.com/aws/en/query-federation/networking.md).
* Databricks compute must use Databricks Runtime 15.2 or above and **Standard** or **Dedicated** access mode.
* SQL warehouses must be pro or serverless and must use 2024.30 or above.

Permissions required:

* To create a connection, you must be a metastore admin or a user with the `CREATE CONNECTION` privilege on the Unity Catalog metastore attached to the workspace. In workspaces that were enabled for Unity Catalog automatically, workspace admins have the `CREATE CONNECTION` privilege by default.
* To create a foreign catalog, you must have the `CREATE CATALOG` permission on the metastore and be either the owner of the connection or have the `CREATE FOREIGN CATALOG` privilege on the connection. In workspaces that were enabled for Unity Catalog automatically, workspace admins have the `CREATE CATALOG` privilege by default.

Additional permission requirements are specified in each task-based section that follows.

## Create a Salesforce connected app

Salesforce connected apps allow an external application to integrate with Salesforce using APIs and standard protocols. This section describes how to create a connected app using SSO to allow Databricks to authenticate with Salesforce.

> [!NOTE]
>
> For more detailed instructions, see [Create a Connected App](https://help.salesforce.com/s/articleView?id=sf.connected_app_create.htm\&type=5) in the Salesforce Data 360 documentation.

To create a Salesforce connected app, do the following:

1. In the upper-right of Data 360, click **Setup**.
2. Under **Platform Tools**, click **Apps > App Manager**.
3. Click **New Connected App**.
4. Enter a **Name** and a **Contact** email address.
5. Enable **OAuth settings**:
   1. Enter the **Callback URL**, in the following format: `https://<databricks_instance_url>/login/oauth/salesforce.html`. For example: `https://cust-success.cloud.databricks.com/login/oauth/salesforce.html`.
   2. (Optional) If you plan to use SQL to create the Databricks connection and the foreign catalog in the next step, your Salesforce Connected App also needs to support the redirect URI `https://login.salesforce.com/services/oauth2/success`. This isn't needed if you plan to use Catalog Explorer to create the Databricks connection and the foreign catalog. Databricks recommends using Catalog Explorer because it requires fewer manual steps than other methods.
   3. Add the following **Scopes**:
      * Access all Data 360 API resources (**cdp\_api**)
      * Manage user data via APIs (**api**)
      * Perform ANSI SQL queries on Data 360 data (**cdp\_query\_api**)
      * Perform requests at any time (**refresh\_token, offline\_access**)
   4. Click **Save**.
   5. Click **Continue**.
6. On the **Connected App overview** page, click **Manage Consumer Details**. You will prompted to authenticate.
7. Upon successful authentication, **Consumer key** and **Consumer secret** are revealed. Save these values. You'll need them when you create a Databricks connection.

## <a id="connection" />Create a Databricks connection

A connection specifies a path and credentials for accessing an external database system. To create a connection, you can use Catalog Explorer or the `CREATE CONNECTION` SQL command in a Databricks notebook or the Databricks SQL query editor.

> [!NOTE]
>
> You can also use the Databricks REST API or the Databricks CLI to create a connection. See [POST /api/2.1/unity-catalog/connections](https://docs.databricks.com/api/workspace/connections/create) and [Unity Catalog commands](https://docs.databricks.com/aws/en/dev-tools/cli/commands.md#unity-catalog-commands).

**Permissions required:** Metastore admin or user with the `CREATE CONNECTION` privilege.

### Catalog Explorer

1. In your Databricks workspace, click ![Data icon.](https://docs.databricks.com/aws/en/images/product-icons/DataIcon.svg) **Catalog**.
2. At the top of the **Catalog** pane, click the ![Add or plus icon](https://docs.databricks.com/aws/en/images/icons/add-icon.png) **Add** icon and select **Create a connection** from the menu.
3. On the **Connection basics** page of the **Set up connection** wizard, enter a user-friendly **Connection name**.
4. Select a **Connection type** of **Salesforce Data 360**.
5. (Optional) Add a comment.
6. On the **Authentication** page, enter the following connection properties for your Salesforce Data 360:
   * (Optional) Select **Is sandbox**.
   * **Client ID**: Salesforce connected app consumer key.
   * **Client secret**: Salesforce connected app consumer secret.
   * **Client scope**: `cdp_api api cdp_query_api refresh_token offline_access`
7. Click **Sign in with Salesforce**.
8. (OAuth) You are prompted to sign in to Salesforce Data 360 using your SSO credentials.
9. Upon successful login you are directed back to the Databricks **Set up connection** wizard. The **Sign in with Salesforce** button has been replaced with a `Successfully authorized` message.
10. Click **Create connection**.
11. On the **Catalog basics** page, enter a name for the foreign catalog. A foreign catalog mirrors a database in an external data system so that you can query and manage access to data in that database using Databricks and Unity Catalog.
12. Enter the Salesforce data space.
13. (Optional) Click **Test connection** to confirm that it works.
14. Click **Create catalog**.
15. On the **Access** page, select the workspaces in which users can access the catalog you created. You can select **All workspaces have access**, or click **Assign to workspaces**, select the workspaces, and then click **Assign**.
16. Change the **Owner** who will be able to manage access to all objects in the catalog. Start typing a principal in the text box, and then click the principal in the returned results.
17. Grant **Privileges** on the catalog. Click **Grant**:
    1. Specify the **Principals** who will have access to objects in the catalog. Start typing a principal in the text box, and then click the principal in the returned results.
    2. Select the **Privilege presets** to grant to each principal. All account users are granted `BROWSE` by default.
       * Select **Data Reader** from the drop-down menu to grant `read` privileges on objects in the catalog.
       * Select **Data Editor** from the drop-down menu to grant `read` and `modify` privileges on objects in the catalog.
       * Manually select the privileges to grant.
    3. Click **Grant**.
18. Click **Next**.
19. On the **Metadata** page, specify tags key-value pairs. For more information, see [Apply tags to Unity Catalog securable objects](https://docs.databricks.com/aws/en/database-objects/tags.md).
20. (Optional) Add a comment.
21. Click **Save**.

### SQL

Databricks recommends using Catalog Explorer to create the connection and the foreign catalog because it requires fewer manual steps than other methods.

If you plan to use SQL to create the Databricks connection and the foreign catalog, your Salesforce Connected App needs to support the redirect URI `https://login.salesforce.com/services/oauth2/success`. This isn't needed if you use Catalog Explorer.

1. Generate PKCE code verifier and code challenge codes. You can do this using an online tool such as [https://tonyxu-io.github.io/pkce-generator/](https://tonyxu-io.github.io/pkce-generator/) or by running the following Python script:

   ```python
   %python

   import base64
   import re
   import os
   import hashlib

   code_verifier = base64.urlsafe_b64encode(os.urandom(40)).decode('utf-8')
   code_verifier = re.sub('[^a-zA-Z0-9]+', '', code_verifier)

   code_challenge = hashlib.sha256(code_verifier.encode('utf-8')).digest()
   code_challenge = base64.urlsafe_b64encode(code_challenge).decode('utf-8')
   code_challenge = code_challenge.replace('=', '')
   print(f"pkce_verifier  = \"{code_verifier}\"")
   print(f"code_challenge = \"{code_challenge}\"")
   ```

2. Visit the following URL and authenticate with your Salesforce credentials to get the `authorization_code` (replace `<client_id>` and `<code_challenge>` with your parameters).

   ```
   https://login.salesforce.com/services/oauth2/authorize
   ?client_id=<client_id>
   &redirect_uri=https://login.salesforce.com/services/oauth2/success
   &response_type=code
   &code_challenge=<code_challenge>
   ```

   A URL-encoded authorization code is visible in the redirected URL.

3. Run the following in a notebook or the Databricks SQL query editor:

   ```sql
   CREATE CONNECTION '<Connection name>' TYPE salesforce_data_cloud
   OPTIONS (
     client_id '<Consumer key from Salesforce Connected App>',
     client_secret '<Consumer secret from Salesforce Connected App>',
     pkce_verifier '<pkce_verifier from the last step>',
     authorization_code '<URL decoded `authorization_code`, should end with == instead of %3D%3D>',
     oauth_redirect_uri "https://login.salesforce.com/services/oauth2/success",
     oauth_scope "cdp_api api cdp_query_api refresh_token offline access",
     is_sandbox "false"
     );
   ```

   Databricks recommends that you use Databricks [secrets](https://docs.databricks.com/aws/en/security/secrets/index.md) instead of plaintext strings for sensitive values like credentials. For example:

   ```sql
   CREATE CONNECTION '<Connection name>' TYPE salesforce_data_cloud
   OPTIONS (
     client_id secret ('<Secret scope>','<Secret key client id>'),
     client_secret secret ('<Secret scope>','<Secret key client secret>'),
     pkce_verifier '<pkce_verifier from the last step>',
     authorization_code '<URL decoded `authorization_code`, should end with == instead of %3D%3D>',
     oauth_redirect_uri "https://login.salesforce.com/services/oauth2/success",
     oauth_scope "cdp_api api cdp_query_api refresh_token offline access",
     is_sandbox "false"
     );
   ```

   For information about setting up secrets, see [Secret management](https://docs.databricks.com/aws/en/security/secrets/index.md).

## Create a foreign catalog

> [!NOTE]
>
> If you use the UI to create a connection to the data source, foreign catalog creation is included and you can skip this step.

A foreign catalog mirrors a database in an external data system so that you can query and manage access to data in that database using Databricks and Unity Catalog. To create a foreign catalog, you use a connection to the data source that has already been defined.

To create a foreign catalog, you can use Catalog Explorer or the `CREATE FOREIGN CATALOG` SQL command in a Databricks notebook or the SQL query editor. You can also use the Databricks REST API or the Databricks CLI to create a catalog. See [POST /api/2.1/unity-catalog/catalogs](https://docs.databricks.com/api/workspace/catalogs/create) and [Unity Catalog commands](https://docs.databricks.com/aws/en/dev-tools/cli/commands.md#unity-catalog-commands).

**Permissions required:** `CREATE CATALOG` permission on the metastore and either ownership of the connection or the `CREATE FOREIGN CATALOG` privilege on the connection.

### Catalog Explorer

1. In your Databricks workspace, click ![Data icon.](https://docs.databricks.com/aws/en/images/product-icons/DataIcon.svg) **Catalog** to open Catalog Explorer.
2. In the upper right, click **Create Catalog**.
3. Enter the following properties for your Salesforce Data 360 catalog.
   * **Catalog name**: A user-friendly name for the catalog.
   * **Type**: `Foreign`.
   * **Connection name**: The name of the connection the catalog will be created on.
   * **Dataspace**: A Salesforce data space.
4. Click **Create**.

### SQL

Run the following SQL command in a notebook or the SQL query editor. Items in square brackets are optional.

```sql
CREATE FOREIGN CATALOG [IF NOT EXISTS] '<catalog-name>' USING CONNECTION '<connection-name>'
OPTIONS (dataspace '<dataspace>');
```

Replace the following values:

* `<catalog-name>`:
* `<connection-name>`:
* `<dataspace>`: Salesforce data space. For example, `default`.

## Supported pushdowns

The following table lists the pushdown operations supported for Salesforce Data 360, along with the compute required for each.

| Pushdown                                                                                                                                                                         | Supported compute                                                                          |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| Aggregates                                                                                                                                                                       | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Arithmetic operators<br />(such as +, -, \*, %, /) — not supported if [ANSI mode](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-ansi-compliance.md) is disabled | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Boolean operators<br />(such as =, \<=>, \<, \<=, >, >=)                                                                                                                         | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Contains, Startswith, Endswith                                                                                                                                                   | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Filters                                                                                                                                                                          | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Limit                                                                                                                                                                            | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Mathematical functions<br />(SIN, COS — partial support, filter expressions only)                                                                                                | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Miscellaneous functions<br />(Cast — partial support, filter expressions only)                                                                                                   | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Offset                                                                                                                                                                           | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Projections                                                                                                                                                                      | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Sorting, when used with limit                                                                                                                                                    | ![Supported](https://docs.databricks.com/aws/en/images/icons/check-icon.png) All compute   |
| Joins                                                                                                                                                                            | ![Not supported](https://docs.databricks.com/aws/en/images/icons/x-icon.png) Not supported |
| Window functions                                                                                                                                                                 | ![Not supported](https://docs.databricks.com/aws/en/images/icons/x-icon.png) Not supported |

## Data type mappings

When you read from Salesforce Data 360 to Spark, data types map as follows:

| Salesforce Data 360 type        | Spark type            |
| ------------------------------- | --------------------- |
| `Boolean`                       | `BooleanType`         |
| `Date`                          | `DateType`            |
| `Datetime`                      | `TimestampType`       |
| `Email`, `Phone`, `Text`, `Url` | `StringType`          |
| `Number`, `Percent`             | `DecimalType(38, 18)` |

## Limitations

* Only one Salesforce data space per Databricks catalog is supported.
* In Databricks Runtime 16.1 and older, case-sensitive table and schema names are not supported. This includes names that have upper case letters on Salesforce Data 360. For example, `MyTable` is not supported.
