# Org Connections

A Slack app in a workspace is allowed to connect to one or more orgs for all Slack users in that workspace. When working with a Slack app,
users are granted the power to connect, disconnect, or reconnect to different orgs. For example:

- Your org or scratch org expires or is no longer valid.
- You [removed the app](https://slack.com/help/articles/360003125231-Remove-apps-and-custom-integrations-from-your-workspace#remove-an-app-1), which uninstalls and disconnects the app from the org.

Slack prompts you to log into a new org if your connected org has expired or is no longer valid.

## Connect to an Org

When you run your Slack app for the first time a prompt is shown to connect to your Salesforce org. Whether it's through a slash command in a channel or accessing the Home page in the app, Slack prompts you to connect.

![Prompt to connect to an org](https://a.sfdcstatic.com/developer-website/sfdocs/salesforce-slack-sdk/media/pleaseConnectMsg.png)

Follow the on-screen instructions to connect your Slack workspace to your Salesforce org.

After connecting to your Salesforce org, another prompt grants your Slack app permission to access the workspace. If your app includes the `chat:write` scope, you must also select a channel to post to.

Finally, you get a prompt to allow Slack to access your Salesforce account. Following this step, you can run your app in the channel you selected.

:::note
If you have to connect an org you previously connected to, you must use the same Salesforce user that was used when you initially connected.
:::

## Disconnecting an Org

Disconnecting an org includes disassociating the app and workspace from the org, enabling you to
target new orgs with a new user.

To disconnect your Slack app from an org, make sure you configure your Slack app to subscribe to
the corresponding bot events and then invoke the app uninstall.

- Subscribe to the `app_uninstalled` and `tokens_revoked` bot events. Adding these events helps your app to know when your Slack app is uninstalled or when the API tokens for your app are revoked. See [Choosing event subscriptions](https://api.slack.com/apis/connections/events-api#the-events-api\_\_subscribing-to-event-types\_\_choosing-event-subscriptions).
- Uninstall your app by following the steps at [Remove apps and custom integrations from your workspace](https://slack.com/help/articles/360003125231-Remove-apps-and-custom-integrations-from-your-workspace#remove-an-app-1).

## Connect to Multiple Orgs

Connect up to five Salesforce orgs to a single Slack Workspace with the Salesforce for Slack Multi-Org management feature. The Salesforce for Slack app provides
Salesforce Admins and standard users the ability to have access to multiple Salesforce orgs in Slack. Standard users can set their Preferred org connection. Users
can connect or disconnect their individual user account from any org that they’re connected to.

To initially connect a Salesforce org to Slack you must be a Salesforce Admin or have the **Manage Slack App Organization Connections for Slack Apps**
permission.

1. Click **Connect New Org**.
2. Sign into the org that you would like to connect to Slack.
3. Click **Allow** to connect your org to Slack.
4. Agree to Slack accessing Salesforce data by clicking the checkbox and then Allow.
5. A confirmation message appears and you can close the browser window.

## View the List of Connected Orgs

1. Open Salesforce for Slack in your Slack workspace.
2. Select the Home tab in the app.
3. Click **Manage Orgs**. The management window appears with an updated list of current connections.

## Manage All Existing Connections

The Multi-Org feature allows you to connect multiple Salesforce orgs to one Slack workspace.
To access this feature use a button on the Salesforce for Slack Home tab or a slash command.

To Manage an Existing Connection:

1. Open Salesforce for Slack in your Slack workspace.
2. Select the Home tab in the app.
3. Click **Manage Orgs**. The management window appears with an updated list of current connections.
4. Select your Salesforce org and click **Manage** to see additional details.

As a Standard User you can:

- Connect and disconnect your Salesforce user.
- Set the selected connection as the preferred.
- View the selected preferred Salesforce org.

A Salesforce admin can also perform the following tasks:

- Disconnect a connection.
- Set a selected connection as the default connection.
- View the selected default connection.

## Preferred vs. Default Orgs

The Preferred and Default labels determine which Salesforce org handles any action based on the user preference.

- Preferred: The Preferred org takes the highest precedence. The user sets their own Preferred org. When slash commands or shortcuts are run, the Preferred org is used.
- Default: The Default org is set by the Salesforce Admin. If a Preferred org isn’t set, the Default org is used as an alternative.
