> Documentation index: https://metorial.com/llms.txt. Every page is available as Markdown by adding .md to its URL.

# Connect Salesforce to your AI agents with per-user OAuth
URL: https://metorial.com/docs/platform/integrations/salesforce

Publish Salesforce in a Metorial portal so each employee signs in to production, a sandbox or My Domain, with your own External Client App and read-only tools.

---

To connect Salesforce, an admin shares the Salesforce integration in a portal and each employee signs in with their own Salesforce user. The agent then queries and changes records with that user's profile, permission sets and sharing rules, so it never sees a record the person cannot see. The integration works with production orgs, sandboxes and My Domain login hosts.

**What you'll learn**

* How an admin publishes Salesforce and how an employee connects
* How to point the integration at a sandbox or your My Domain
* How to use your own External Client App and block write tools

**Before you start**

* A [portal](https://metorial.com/docs/platform/workforce/portals) with at least one access group
* A Salesforce user with API access for each person who will connect
* To use your own app: permission to create External Client Apps in **Setup**

## Sign-in method

Salesforce has one method, **OAuth 2.0**. It uses the authorization code flow with PKCE and a refresh token. There is no username and password method and no API token method.

## Choose the Salesforce environment

The integration has an `environment` setting that decides where people sign in.

| `environment`          | Sign-in host                                                            |
| ---------------------- | ----------------------------------------------------------------------- |
| `production` (default) | `login.salesforce.com`                                                  |
| `sandbox`              | `test.salesforce.com`                                                   |
| `custom`               | The host in `customDomain`, for example `<my-domain>.my.salesforce.com` |

Use `custom` when your org blocks sign-in through the shared login hosts. `customDomain` accepts the short name, the full host or a URL. A second setting, `apiVersion`, sets the Salesforce REST API version and defaults to `v62.0`.

To offer production and a sandbox side by side, share two Salesforce integrations with different environments and name them clearly.

## Admin: publish Salesforce in a portal

### In the dashboard

#### 1. Open Shared Resources

Open **Workforce**, choose the portal, and select **Shared Resources** under **Access**.

#### 2. Share a new integration

Select **Share a Resource**, then **New Integration**, and choose Salesforce. Set the environment. For how members connect, choose **Each person connects**.

To have every agent act as one Salesforce integration user, choose **Shared connection** and connect it once with that user.

#### 3. Choose who gets it

Add the access groups that should see Salesforce.

### With the CLI

The CLI cannot create the per-user integration. Once it exists, list who has it:

```bash
metorial-admin portals access list <portal-id> --type provider_template --search salesforce
```

## Employee: connect your Salesforce user

### In the portal

#### 1. Open Salesforce in the catalog

Sign in to your portal and open Salesforce.

#### 2. Authenticate

Under **Quick setup**, select **Authenticate**. A Salesforce tab opens. Sign in and allow access.

#### 3. Confirm

The status changes to **Configured**. If it later reads **Needs reconnect**, select **Reconnect**.

### With the CLI

```bash
metorial catalog search salesforce
metorial setup <catalog-item-id>
```

## Scopes

| Scope                | What it allows                          | Requested by default |
| -------------------- | --------------------------------------- | -------------------- |
| `api`                | REST API access to data                 | Yes                  |
| `refresh_token`      | Stay connected without signing in again | Yes                  |
| `openid`, `profile`  | Identify the signed-in user             | Yes                  |
| `chatter_api`        | Chatter feeds and posts                 | No                   |
| `wave_api`           | Analytics                               | No                   |
| `cdp_api`            | Data Cloud                              | No                   |
| `pardot_api`         | Account Engagement                      | No                   |
| `custom_permissions` | Read the user's custom permissions      | No                   |
| `full`               | Everything the user can do              | No                   |

Salesforce scopes do not separate reading from writing. `api` covers both. To limit what the agent can change, use the Salesforce user's permissions and Metorial's tool permissions, described below.

## Use your own External Client App

### 1. Start the credentials in Metorial

In the dashboard, select **Settings**, then **Organization Settings**. Under **Integrations and MCP**, select **Provider Auth**, then **Create Auth Credentials**. Choose Salesforce and copy the **Redirect URI**.

### 2. Create the app in Salesforce

In Salesforce **Setup**, enter **App Manager** in Quick Find and open it. Select **New External Client App**. Enter a name, an API name and a contact email, and keep the distribution state **Local**.

### 3. Turn on OAuth

In the app's **OAuth Settings**, select **Enable OAuth**. Paste the redirect URI from Metorial into **Callback URL**. Select the OAuth scopes you plan to request, including the one for refresh tokens. Select **Require Secret for the Web Server Flow**, **Require Secret for Refresh Token Flow** and **Require Proof Key for Code Exchange (PKCE) extension for Supported Authorization Flows**. Save.

### 4. Finish in Metorial

Copy the app's consumer key and consumer secret from its OAuth settings. In Metorial, enter a **Name**, the consumer key as **Client ID** and the consumer secret as **Client Secret**, select the same scopes, and select **Create**.

Salesforce's steps are in [Create a local external client app](https://help.salesforce.com/s/articleView?id=xcloud.create_a_local_external_client_app.htm\&type=5) and [Configure the OAuth settings](https://help.salesforce.com/s/articleView?id=xcloud.configure_external_client_app_oauth_settings.htm\&type=5).

An app created in one org is known only to that org. If you connect production and a sandbox, check that the app exists in both, or create one in each and store two sets of credentials.

## Make the connection read-only

Open the integration's **Tool Filters** and set the write and destructive tool groups to **Reject**. Read tools such as `query_records`, `get_record`, `search_records` and `describe_object` stay available. Tools such as `create_record`, `update_record` and `delete_record` are no longer offered to any agent. See [Tool permissions](https://metorial.com/docs/platform/guides/tool-permissions).

For a stronger guarantee, also connect with a Salesforce user whose profile is read-only on the objects that matter.

## Check it worked

```bash
metorial list salesforce
metorial tools <integration-id>
metorial call <integration-id> get_org_limits
metorial call <integration-id> query_records -d '{"soql": "SELECT Id, Name FROM Account LIMIT 5"}'
```

`get_org_limits` takes no input and proves the token works. The query proves the user can read data.

## Next steps

* [Create custom OAuth credentials](https://metorial.com/docs/platform/integrations/create-custom-oauth-credentials)
* [Per-user OAuth](https://metorial.com/docs/platform/guides/per-user-oauth)
* [Connect an app from the terminal](https://metorial.com/docs/platform/cli/connect-an-app)
* [Review connection logs](https://metorial.com/docs/platform/integrations/review-connection-logs)