Blog

Get Our Latest Thoughts & Opinions

Salesforce to Slack Integration

  • 29 Jul 2021
  • admin

Staying organised can be a challenge in a fast-moving Salesforce org.  We can sometimes find ourselves behind the curve with a client/case/opportunity/etc. Maybe we haven’t been checking a report frequently enough or the email notifications we’ve set up have gotten lost in the pile.  

What’s more, many of these solutions require a lot of work to set up and only offer a limited amount of control. It makes sense then that we try to send notifications to the applications we’re using throughout the day. 

Fig 1

That’s why we’ve come up with a quick & easy way to get notifications directly in Slack as soon as something of note occurs in Salesforce.  This solution revolves around an invocable action that can be easily configured by any Salesforce administrator and incorporated into a flow or process to send messages to a public or private Slack channel &/or an individual user/group of users.  

There’s a great deal of flexibility here and you can use the solution with all the functionality already on offer with flows and process builders.  What this means is that once the initial setup in Slack and Salesforce is complete; with a few clicks we can determine when a notification is sent, to who, and what the message contains (with highly dynamic messages).

The solution comprises three parts – a Slack environment, a Slack app, and your Salesforce org. In concise terms the steps required for setup are:

  1. Create a Slack app and install it into your environment. Grant this app access to any private channels you wish to post to.

  2. Download the package within your Salesforce environment.

  3. Create a remote site setting for Slack.com.

  4. Provide Salesforce with the Slack bot token via a custom setting.

Once the above has been completed all that’s required is to add an action to a flow (Fig 2) or a process (fig 3) and configure the parameters.

Fig 2

Fig 3

A Closer Look at the Apex Action

As mentioned above, this solution works by adding an Apex action to a flow or process.  The real magic happens when we configure the action’s parameters.  As can be seen in Fig 4 the action takes four parameters.  

Fig 4

Message to be sent

This required parameter refers to the message that will be seen in Slack.  We can enter a direct value (for example “My message to be sent”) or a more dynamic approach such as a custom label.  For further detail on formatting dynamic messages, please refer to the ‘Dynamic Messaging’ section below.

Record Id

This required parameter represents the record of what caused the process or flow to fire.

Channel Name

This optional parameter refers to the Slack channel you wish to post to.  Please note that the Slack application must be added to private channels in order to successfully post to that channel.

User(s) to post to.  Enter a user or public group name

This optional parameter can be used when you wish to notify a user or group of users as opposed to a channel.  A username can be entered to notify an individual user or alternatively the name of a public group can be entered to directly message multiple users.

Dynamic Messaging

To utilise the power of dynamic messages we can use custom labels and the solutions merge fields.  The solution can handle three types of merge field;

{#user} - refers to the running user (the user who cause the process/flow to commence)

{#record} - refers to the record that causes the process/flow to begin

{#link:} – a prefix which when preceded by a record ID outputs a clickable link to that record

These three merge fields are detailed in Fig5 below.

Fig 5 (See output in Fig 1)

For even more dynamism, we can use cross object relationships to reach across multiple objects to obtain a value for our message (for example {#Record.Parent.Name}).  A custom label containing cross object reference can be seen in Fig 6 below.  As is the limitation within Salesforce, the total number of cross object relationships in a single search is limited to five.

Fig 6

Once our custom label containing our dynamic message is complete, we enter it into the Message to be sent parameter, as can be seen in Fig 4.  Who receives the message depends on the values entered in the Channel Name & User(s) to post to… parameters (also visible in Fig 4).  Using these two parameters we can post to a channel, individual, or group of individuals (create a public group containing the desired users & enter the public group name into the parameter).  Note that it is possible to post to both a Slack channel and also a user or group of users.

If you have any questions about this solution or would like more details please feel free to reach out to us.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Today's post is by one of our Salesforce Developer, Paraic Cooney.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

As always, thanks for reading, if you enjoyed this post please feel free to share it and tag us @Pexlify

Pexlify is a Salesforce Platinum Partner in the UK & Ireland. 

Want to know more about our Salesforce Solutions? Contact us today to set up a hassle-free consultation.

Get In Touch

Discover how Pexlify can create digital experiences that transforms and optimises your business with Salesforce.

Get Started