Salesforce to Slack Integration Using Apex and Named Credentials
Introduction: Why Integrate Salesforce with Slack?
In today’s fast-paced digital environment, real-time collaboration is essential for any successful business. Sales, support, and service teams rely heavily on instant notifications to stay aligned, respond faster, and act with context. While Salesforce is the backbone of customer data and case management, Slack is the nerve center of team communication.
By integrating Salesforce with Slack, businesses can:
- Notify teams instantly when critical records are created or updated.
- Connect the dots between data and discussion—without switching tools.
- Reduce response times on high-priority issues like escalated cases.
- Eliminate manual work involved in sending updates via email or chat.
For example, when a high-priority support case is created in Salesforce, your support channel in Slack should light up immediately—no delays, no toggling between tools.
This guide walks you through how to achieve that integration using Apex, Named Credentials, and a Slack webhook, without using any third-party apps or AppExchange solutions.
Use Case
“When a new Case is created in Salesforce with Priority = High, a formatted message should be posted in a specific Slack channel (e.g., #support-alerts).”
Prerequisites
✅ Slack:
A Slack workspace
An Incoming Webhook URL
→ You can create one from: Slack Incoming Webhooks
✅ Salesforce:
- Developer Org or Sandbox
- Admin permissions
- External Credential
- Named Credential
Step 1: Create a Slack App and Get Bot Token
- Go to: Slack Apps Page
- Click Create New App → From Scratch
- Set App Name and Workspace.
- Go to OAuth & Permissions → Add Scopes:
chat:write
channels:read
- Install App to Workspace → Copy Bot User OAuth Token (starts with
xoxb-...
)
Check out the screenshot below:
Step 2: Create an External Credential (Required)
Before creating a Named Credential, we must define an External Credential to securely describe how Salesforce connects to the external service (Slack).
- Go to Setup → External Credentials
- Click New External Credential
- Fill in:
- Label
- Name
- Authentication Protocol
- Click Save
Step 2.1: Create Principals in Related External Credential
- Parameter Name
- Sequence Number
- Identity Type
- Add Authentication Parameters
- Parameter 1 Name
- Value
- Click Save
Step 2.2: Create Custom Headers in Related External Credential
- Name
- Value
- Sequence Number
- Click Save
Step 3: Create a Named Credential
- Go to Setup → Named Credentials
- Click New Named Credential
- Configure as follows:
- Label
- Name
- URL
- Enable for Callouts – Enabled
- External Credential – Select your External Credential
- Click Save
Step 4: Assign Credential Access via Profile
To allow users (or background processes like triggers) to use this external credential:
- Go to Setup → Profiles
- Choose the System Administrator profile (or your active user’s profile)
- Under Enabled External Credential Principal Access, click Edit
- Add Your External Credential and click Save
✅ Now your org can use the Named Credential connected to this External Credential.
Step 5: Create Apex Class for Sending Slack Notifications
Step 6: Create a Handler for Case Trigger
Step 7: Create the Trigger on Case
Test It Out
- Go to App Launcher → Cases
- Create a new Case
- Set Priority = High
- Save and switch to Slack
✅ You’ll see a Slack message in #support-alerts
Below is a demo video showcasing how this integration works.
Conclusion:
Integrating Salesforce with Slack streamlines internal communication by instantly surfacing business-critical events — like high-priority support cases — to the right teams in real time.
Here’s how this integration benefits your business:
- Faster response times – Teams are instantly notified about critical updates
- Improved team alignment – Everyone stays informed without manual follow-ups
- Increased visibility – Greater transparency across departments and workflows
- Reduced manual effort – Automate notifications, reduce human error
Whether you’re in support, sales, or operations — empowering your teams with real-time Slack alerts from Salesforce can transform the way you work.
Let your Salesforce talk to Slack — and make every alert count!