Collaboration tools have become essential in today’s workplace. Slack and Salesforce are two of the most popular tools used by businesses. Integrating Slack with Salesforce can improve communication, streamline workflows, and increase productivity.
Why Integrate Slack with Salesforce?
Integrating Slack with Salesforce offers many benefits, such as:
Sales reps can receive real-time updates on leads and opportunities in Slack. They can also communicate with their team members directly in Slack, without having to switch between different tools.
Support teams can create cases and assign them to team members directly from Slack. This reduces the time it takes to create a case and ensures that the case is assigned to the right team member.
A salesforce integration service consultant in USA suggests Integrating Slack with Salesforce as it eliminates the need for manual data entry, which can be time-consuming and prone to errors. This allows teams to focus on more important tasks.
Requirement: My requirement is to create a new event for an account in Salesforce when a new message is generated in a Slack channel with the same name as the account record. To do this, I will need to integrate Slack with Salesforce.
Solution: In my requirement, I will create an Apex class that is triggered at specific intervals, such as every hour or half hour. When the class runs, it should fetch all new messages in a Slack channel that arrived during that particular interval.
The first step in the integration process is to create a new app in Slack. To do this, visit https://api.slack.com/apps and create a new app. Slack will provide you with a Client ID and Client Secret Key, which you will need in the further steps of the integration process.
In addition, you will need to set the appropriate scope for the app in the OAuth & Permissions section of the app settings. This will ensure that the app has the necessary permissions to access and modify the data in your Slack workspace and Salesforce org.
Bot Token Scopes
This slack app also provides you with a User OAuth Token which will be used in further steps.
The first step is to obtain all channel IDs from Slack because we want the message to arrive in any Slack channel that is used in Salesforce.
To do this, we need to use the SLACK_API_TOKEN variable, which is the Slack API token that you obtain from the Slack app. We can make HTTP requests to obtain all channel IDs from Slack.
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setHeader(‘Authorization’, ‘Bearer ‘ + SLACK_API_TOKEN);
HTTPResponse res = http.send(req);
Map<String, Object> responseMap = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());