Getting real time notifications when critical events occur in your Salesforce Org can be crucial for your organization's ongoing success. Salesforce offers some built in functionality for messaging, however this can at times be cumbersome for users to manage and cause unwanted delays in the transfer of information. Because many organizations use Slack as their primary messaging channel, it would make sense to send certain critical events from your Salesforce Org directly to team members in Slack.
In this article we will create a simple flow in Salesforce that will send a simple Slack message to a Sales slack channel every time a new lead is created. In order to do so, we will follow the following steps:
In order to give Salesforce the necessary permissions to post messages to our Slack Workspace, we first need to create a Slack App.
Now that our app is created, we simply need to give it a few special permissions to allow external sources to post messages.
Click Add an OAuth Scope and add the following scopes to your app:
Great! Now you're ready to install this app to your Workspace. Scroll up and click Install App to Workspace.
When installing the app, Slack will ask which channel you would like the app to be installed to. This is important because the app will only post messages to channels that it has been invited to. For this demo, we have created a channel called new leads which we will be using.
* If you want to use your Slack App in other channels later on, simply navigate to that channel in Slack and enter /invite @YourAppName in the message bar, then your app will be added.
Wow! That was easy! You will now see that an OAuth Token has been created for you. Copy that token and save it somewhere safe; we will need it for later.
You can install the Send Slack Messages Package into your Salesforce Organization by navigating to the link below:
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t2H00000126Q7QA
It's as simple as that! At the click of a button the app will be installed to your org. If you inspect the contents of the package you will find the following components being installed:
In this section we will demonstrate the power of this new Unlocked Package with just a few simple clicks.
Note that while selecting the object, you can specify the conditions upon which this flow will be run. This may be useful in order to define when a message should be sent. For example, if a salesperson creates the lead, then there is no need to send them a Slack message about it. However, if the lead comes in from an external source, like web to lead, then a Slack message should be sent notifying the salesperson of the external lead. For simplicities sake, we will ignore conditions for now and set Condition Requirements to none.
Now all that's left to do is configure the action and create the message we want to send!
A New Lead was created for {!$Record.FirstName} {!$Record.LastName}! <{YOUR ORG DOMAIN}/lightning/r/Lead/{!$Record.Id}/view|Click Here to See it Now!>
Make sure to replace {YOUR ORG DOMAIN} with the base URL of your org. For example, mine would look like: https://testhalosight.lighting.force.com/lightning/r/Lead/{!Record.Id}/view
As mentioned above, you may use the mrkdwn language to style the message being sent to Slack. In this example we are trying to send a link which references the new Lead record. In order to create a url, the syntax looks like this:
<www.google.com|Click Here to Go to Google!>
Once sent to slack, the above message would look like this:
The rest of the setup is fairly straightforward. Click here for more information on the following parameters.
And just like that, you're done! Make sure to save and activate the flow, and now you're ready to test the action by creating a new Lead in your org.
If a message does not get sent to Slack, go to the Slack Channel you are trying to post in and type /invite @YourAppName into the message bar to allow the app to post into the channel. You should be able to see in Slack that the app was added.
If everything works as expected, you should see a new message in Slack when a Lead is created.
Amazing! After just a little bit of setup, you now have a powerful APEX Action in your org that can be reused anywhere, and best of all, it's absolutely free! Halosight works hard to give you the most value out of your Salesforce Organization, go to https://www.halosight.com to learn more about us.
For more in depth information about the Send Slack Message component, view our documentation in GitHub.