Managed Services Technical Consultant, Vivek Makkar, explains how he integrated our internal Slack and Salesforce applications so that we can receive notifications of urgent emails via a Slack channel
When you’re receiving hundreds of emails a day it can be challenging to get through them all, especially when you are working for one of the most trusted names in the Salesforce service industry. There are critical bug defects that we [developers/consultants] simply cannot miss. But what if there was a way to automate critical alerts to your most frequently used internal communication platform?
At makepositive, our most heavily trafficked internal communication tool is Slack. Recognising this I thought: wouldn’t it be great if we could get notifications concerning urgent emails on one of our Slack channels?
Sounds like a dream, right? Well, when using REST API Integration and webhooks within your environment you can make this dream a reality!
In the toolbox…
Let’s look at the tools required for this integration:
- SLACK: Slack is a collaboration hub that can replace email to help you and your team work together seamlessly. It’s designed to support the way people naturally work together, so you can collaborate with people online as efficiently as you do face-to-face. In the current Covid-19 environment tools like Slack are only becoming more and more important.
- Webhooks: Webhooks are an incredibly useful and a resource-light way to implement event reactions. Webhooks provide a mechanism whereby a server-side application can notify a client-side application when a new event (that the client-side application might be interested in) has occurred on the server like pull requests. Webhooks are also sometimes referred to as “Reverse APIs”.
Wondering what Slack looks like? This should give you an idea:
Let’s take a look at some steps on how to proceed with creating a Slack webhook:
Set up incoming webhooks:
STEP 1 : Create a new Slack app in the workspace where you want to post messages.
STEP 2 : From the Features page, toggle ‘Activate Incoming Webhooks’ to on.
STEP 3 : Click Add ‘New Webhook to Workspace’.
STEP 4 : Pick a channel for the app to post messages to and then click ‘authorise’.
STEP 5 : Use your incoming webhook URL to post a message to Slack.
Here is my webhook configuration for the Salesforce Case integration:
Well Done! We’re now finished with setting everything up on the Slack side.
Now let’s set up your Salesforce code:
Note: We have configured a Slack webhook, check it out if you get stuck.
Now that we’ve done most of the prep-work, let’s log in to Salesforce and bring this integration to life.
STEP 1: Create an Apex class (An Apex class is a template or blueprint from which Apex objects are created) to enable you to connect or send calls to the Slack webhook with your own designed messages.
This code snippet connects to our Slack webhook.
STEP 2: Create a process builder and call an Apex class that has @Invocable methods which will allow the process builder to discover a class.
Note: You can select any criteria to trigger the process builder. For example, you can trigger it to notify you whenever a new case is being created.
The parameter body is a JSON structure, which you can create to your specific design requirements. You can do this easily from here.
Now, you just need the class SlackCall constructor with the proper parameters. Use the enqueueJob method inside the class. The class is then called by the process builder that has @Invocable method:
And this is how your Slack message will appear:
We have our github repository for reference to all the code, check it out if you get stuck somewhere along the way.
Do you want to learn more about how cutting-edge companies like makepositive use this sort of technology? Check out our other makepositive blogs, which are full of other technical and worker experience resources, or contact us directly at email@example.com.