# Salesforce SOQL

UI Bakery allows you to easily connect to Salesforce SOQL with no need for additional layers like APIs or third-party services. \
You can connect Salesforce SOQL as a [standalone data source](#connecting-salesforce-as-a-standalone-data-source) or via an [HTTP data source](#connecting-salesforce-as-an-http-data-source).

## Configuration

### Connecting Salesforce SOQL as a standalone data source

1. On the **Data sources** page, click **Connect**, and select *Salesforce SOQL* in the Data sources list.
2. Give your data source a name and specify the **Salesforce URL** (optional).
3. Click **Connect to Salesforce** and authorize the access in the Salesforce app.
4. Finally, click **Test connection** to check whether the connection can be established, and then click **Connect Datasource** to complete the setup.

<figure><img src="/files/tioVHQXehTWzT3pSPkvN" alt=""><figcaption></figcaption></figure>

### Connecting Salesforce SOQL as an HTTP data source

#### Prerequisites

First, you need to create a **connected app** in Salesforce SOQL. To do so, follow the instructions below:

1. In *Lightning Experience*, open **Setup**, navigate to **Apps** > **App Manager,** and click **New Connected App**.

<figure><img src="/files/4QDGuZbejPgZanXoXrej" alt=""><figcaption></figcaption></figure>

In *Salesforce Classic*, open **Setup**, navigate to **Build** > **Create** > **Apps**, scroll down to *Connected Apps*, and click **New**.

<figure><img src="/files/loQbjHxDIJj7ecAmLcp3" alt=""><figcaption></figcaption></figure>

2. Specify all the required information in the *Basic Information* section.
3. Next, select the **Enable OAuth Settings** checkbox in the *API* section:
   1. Specify the following **Callback URL** - `https://cloud.uibakery.io/datasource-auth/callback`.
   2. In *Selected OAuth Scopes*, add all the OAuth scopes you need. Make sure to add the `Perform requests at any time` scope.&#x20;

{% hint style="warning" %}
Even though the `Full access` scope is a valid option that you can add, it's important to note that it doesn't grant all the necessary permissions.
{% endhint %}

<figure><img src="/files/LTdeUf6rBFlOdlqc1zkn" alt=""><figcaption></figcaption></figure>

4. Click **Save**.

You'll be redirected to the *Manage Connected Apps* page. There, you can click **Manage Consumer Details** in the *API* section to copy the `Consumer Key` and `Consumer Secret` that will be required later.

#### Connecting the data source

Now, in UI Bakery, follow these steps to configure the Salesforce data source:

1. On the **Data sources** page, click **Connect**, and select *HTTP API* in the Data sources list.
2. In the **Authentication settings** dropdown, select OAuth2.
3. Next, in the **OAuth2 Flow** dropdown, select the flow you need:
   1. *Authorization Code Flow*
   2. *Client Credentials Flow*
   3. *Password Grant*

<details>

<summary><strong>Authorization Code Flow</strong></summary>

1. First, in your Connected App, deselect the **Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows** checkbox in the *API* section and wait for up to 10 min for the changes to take effect.

<figure><img src="/files/v96IEDOMnUgBctlJcGbf" alt=""><figcaption></figcaption></figure>

2. Next, go back to the data source connection window and specify the **Client ID** (=Consumer Key) and **Client secret** (=Consumer Secret) from your connected app.
3. As the **Authorization URL**, specify `https://login.salesforce.com/services/oauth2/authorize`.
4. As the **Access Token URL**, specify `https://login.salesforce.com/services/oauth2/token`.

<figure><img src="/files/l8MihgEKd5fqBizG8Jwy" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary><strong>Client Credentials Flow</strong></summary>

1. First, in your Connected App, select the **Enable Client Credentials Flow** checkbox in the *API* section and wait for up to 10 min for the changes to take effect.

<figure><img src="/files/pjjB2mrI3vqE97RePaq2" alt=""><figcaption></figcaption></figure>

2. Next, also in the Connected app settings you should assign a *Client Credentials User.*

<figure><img src="/files/nMXbnJIo5GrhLizBh6vx" alt=""><figcaption></figcaption></figure>

3. Now, go back to the data source connection window and specify the **Client ID** (=Consumer Key) and **Client secret** (=Consumer Secret) from your connected app.
4. As the **Access Token URL**, specify the following:\
   \
   `https://your_salesforce_domain_url/services/oauth2/token`.

<figure><img src="/files/Y3VwD2S2sLQs562bZ0bt" alt=""><figcaption></figcaption></figure>

</details>

4. Click **Connect to API** first and then **Connect Datasource** to complete the setup.

## Troubleshooting

* If you encounter an error message while testing the connection, double-check that the *Callback URL* and *OAuth scopes* are correctly configured in Salesforce.
* Make sure your Salesforce instance URL ends in `.salesforce.com`.
* Make sure that the correct permissions are granted to the connected app.

## On-premise connection

Due to the on-premise version [limitations](/on-premise/ui-bakery-on-premise.md#limitations), connection to Salesforce SOQL there requires additional setup. Refer to this page for more details:point\_down:

{% content-ref url="/pages/2tCyY82WzJ9buHEbWntB" %}
[Salesforce connection setup](/on-premise/additional-configurations/salesforce-connection-setup.md)
{% endcontent-ref %}

***

## Usage

Once you've established the connection between UI Bakery and Salesforce SOQL, you can start interacting with its data.

If you've connected Salesforce SOQL as a [standalone data source](#connecting-salesforce-as-a-standalone-data-source), the [SQL Query](/reference/working-with-actions/sql-query.md) action type is supported for this data source.

If you've connected Salesforce SOQL as an [HTTP data source](#connecting-salesforce-as-an-http-data-source), the [HTTP Request](/reference/working-with-actions/http-request.md) action type is supported for this data source.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.uibakery.io/reference/data-sources/salesforce.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
