---
title: "Salesforce Email Agent Integration"
description: "Overview"
canonical_url: "https://help.brainfi.sh/articles/salesforce-email-agent-integration-cZiSs3Il9z"
md_url: "https://help.brainfi.sh/articles/salesforce-email-agent-integration-cZiSs3Il9z.md"
---
# Salesforce Email Agent Integration

## Overview

The Salesforce Email integration allows Brainfish to monitor incoming email cases in your Salesforce org and automatically respond with AI-generated answers. Once connected, Brainfish polls for new EmailMessage records on Salesforce Cases, generates a response using your configured knowledge sources, and sends the reply back either as a direct email to the case contact or as an internal case comment.

This article covers the integration settings, how to disconnect, and how to reconnect.

> **Prerequisite:** You must have a Salesforce External Client App with a Client ID and Client Secret already configured. See the companion article [How to Connect Brainfish to Salesforce Using OAuth](https://help.brainfi.sh/en-gb/articles/how-to-connect-brainfish-to-salesforce-using-oauth-C53fd9NHfH) for setup instructions.


---

## Configuration Page Layout

When you open a Salesforce Email agent, the configuration page is divided into three accordion sections on the left and a preview/simulation panel on the right:

| Section | Description |
|----|----|
| **Connection Settings** | Manage the Salesforce OAuth connection. When connected, configure auto-reply, reply action, and queue monitoring. |
| **Agent Settings** | Configure the agent profile, response style, and custom instructions. |
| **Knowledge Settings** | Select which knowledge sources the agent uses to generate responses. |


---

## Connection Settings (When Connected)

Once your Salesforce org is connected, the Connection Settings section displays:

* **Organisation name** and environment type (Production or Sandbox)
* **Connected as** the Salesforce username used during OAuth
* A **Connected** badge confirming the integration is active
* A **Disconnect** button to remove the connection

Below the connection status card, two additional panels appear:

### Enable Auto-Reply

A toggle that enables or disables automatic AI responses to incoming Salesforce email cases.

* **Enabled:** Brainfish actively polls for new incoming email messages on Salesforce Cases and generates AI responses.
* **Disabled:** Brainfish does not poll or respond to cases. The integration remains connected but is effectively paused.

### Reply Action

When auto-reply is enabled, you choose how the AI response is delivered back to Salesforce. There are two options:

| Option | Behaviour |
|----|----|
| **Send email reply** *(default)* | Sends the AI-generated response as an email directly to the case contact. The customer receives the reply in their inbox as if a support agent responded. |
| **Add case comment** | Adds the AI-generated response as an internal comment on the Salesforce Case. The customer does **not** receive an email this is useful for agent-assisted workflows where a human reviews the AI suggestion before sending. |

### Queue Selection

A multi-select dropdown that lets you choose which Salesforce queues the agent should monitor.

* **How it works:** The dropdown lists all Queue-type Groups from your connected Salesforce org (up to 200). You can search and select multiple queues.
* **When queues are selected:** Brainfish only processes email cases that are owned by one of the selected queues. This is useful when you want to limit AI responses to specific support queues (e.g. "Tier 1 Support" or "General Enquiries").
* **When no queues are selected:** Brainfish monitors all incoming email cases across the entire org, regardless of which queue owns them.

> **Tip:** Use queue selection to start with a single low-volume queue and expand to additional queues as you gain confidence in the AI responses.


---

## How the Integration Works End-to-End


1. **Customer sends an email** that creates (or updates) a Salesforce Case.
2. **Brainfish polls** for new EmailMessage records on Cases, optionally filtered by the selected queues.
3. Brainfish maps the case to a conversation thread and **generates an AI response** using the configured knowledge sources and agent settings.
4. Based on the **Reply Action** setting:
   * *Send email reply* → Brainfish creates an outbound EmailMessage on the Case, which Salesforce delivers to the customer.
   * *Add case comment* → Brainfish adds a CaseComment visible to your support team inside Salesforce.
5. The cycle repeats as new email messages arrive on monitored cases.


---

## Disconnecting from Salesforce

To disconnect the integration:


1. Open your Salesforce Email agent configuration page.
2. In the **Connection Settings** section, click the **Disconnect** button (trash icon).
3. A confirmation dialog appears: *"Are you sure you want to disconnect Salesforce? The agent will remain but will need to be reconnected to Salesforce to function."*
4. Click **Disconnect Salesforce** to confirm.

### What Happens When You Disconnect

* The OAuth token is **revoked** on the Salesforce side.
* The integration record and stored authentication credentials are **deleted** from Brainfish.
* The agent itself is **preserved** all agent settings, knowledge source selections, and configuration (auto-reply, reply action, queues) remain intact.
* The agent **stops polling** and will not respond to any new Salesforce cases until reconnected.
* The Connection Settings panel switches to the disconnected view, showing the Client ID, Client Secret, and Sandbox toggle fields.


---

## Reconnecting to Salesforce

If you previously disconnected (or if the connection expired), you can reconnect:


1. Open the Salesforce Email agent configuration page.
2. In the **Connection Settings** section (now showing the disconnected form), enter your **Client ID** and **Client Secret** from your Salesforce External Client App.
3. If your External Client App is in a Sandbox org, toggle **Sandbox environment** on.
4. Click **Connect to Salesforce**.
5. You will be redirected to Salesforce to **authorise** the connection via OAuth.
6. After successful authorisation, Salesforce redirects you back to the agent configuration page.
7. The Connection Settings section now shows the **Connected** status with your org details.

> **Note:** Your previous auto-reply, reply action, and queue settings are retained on the agent. After reconnecting, verify they are still correct and click **Save changes** if any adjustments are needed.

### Re-authorisation Tips

* Use the **same Client ID and Client Secret** as before unless you have rotated your Salesforce app credentials.
* If you switched between Production and Sandbox environments, make sure the **Sandbox environment** toggle matches your External Client App's org type.
* If the OAuth authorisation fails, double-check that the callback URL in your Salesforce External Client App is still correctly configured (see the [OAuth setup guide](https://help.brainfi.sh/en-gb/articles/how-to-connect-brainfish-to-salesforce-using-oauth-C53fd9NHfH)).


---

## Troubleshooting

| Issue | Possible Cause | Resolution |
|----|----|----|
| Connection shows an error after connecting | OAuth token may have expired or been revoked in Salesforce | Disconnect and reconnect using the steps above |
| Queues dropdown shows no options | The connected Salesforce org has no Queue-type Groups, or the connected user lacks permission to query Groups | Verify queues exist in Salesforce Setup and that the connected user has appropriate permissions |
| Auto-reply is enabled but no responses are being sent | Queues may be selected that have no incoming cases, or auto-reply may have been toggled off | Check the queue selection matches queues receiving cases; confirm auto-reply is toggled on |
| "Failed to initiate OAuth flow" error on connect | Client ID or Client Secret may be incorrect | Verify the credentials match your Salesforce External Client App |
| Agent is connected but customers are not receiving email replies | Reply action may be set to "Add case comment" instead of "Send email reply" | Change the Reply Action to "Send email reply" and save |


---

## Related Articles

* [How to Connect Brainfish to Salesforce Using OAuth](https://help.brainfi.sh/en-gb/articles/how-to-connect-brainfish-to-salesforce-using-oauth-C53fd9NHfH) — Setting up the External Client App (Client ID and Secret)
