Last Updated on December 8, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
- How do you post a message to a Slack channel via Salesforce Flow?
Objectives:
After reading this blog, you’ll be able to:
- Understand what a Slack Channel is
- Understand Message Destination and Slack Auth objects
- Use get records to avoid hard coding of Id
- @Mention Slack user in a post
- Send a message to the Slack channel using the record-triggered flow
- Validate Slack user authentication before posting a message
- Use the decision element to validate the get records outcome
- and much more
Business Use Case
Martin Jones is working as a System Administrator at Gurukul on Cloud (GoC). His organization wants to post a message to a Slack Channel opportunities-notifications whenever an Opportunity is successfully closed and the opportunity owner has authenticated Salesforce & Slack.
- Message – <tag opportunity owner>, just closed a new deal. congratulations!! 👏
Pre-requisites:
- The first step is to complete Salesforce for Slack integration.
- The next step is to set up message destinations for Slack channel opportunities-notifications.
What is a Slack Channel?
Slack organizes conversations into dedicated spaces called channels. Channels bring order and clarity to work – you can create them for any project, topic, or team. With the right people and information in one place, teams can share ideas, make decisions, and move work forward.
In Slack, channels can be public or private.
Automation Champion Approach (I-do):
There are a few possible solutions for the above business scenario, but I’ll use After-save Record-Triggered Flow to solve the business requirement.
Before proceeding ahead, you have to understand the following objects.
Object Name | Details |
Message Destination |
A Message Destination represents a conversation in Slack where Salesforce data will be shared. It consists of a specified Slack Workspace and Slack Channel. The destination information will be passed into the Send to Slack invocable method, which will then send Salesforce data to the specified conversation in Slack. |
Slackv2 Auth | OAuth 2.0 is a protocol that lets your app request authorization to private details in a user’s Slack account without getting their password. It’s also the vehicle by which Slack apps are installed on a team. Your app asks for specific permission scopes and is rewarded with access tokens upon a user’s approval. |
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it. Let’s begin building this automation process.
Guided Practice (We-do):
There are 8 steps to solve Martin’s business requirement using Record-triggered Flow. We must:
- Define flow properties for record-triggered flow
- Add a decision element to check if an opportunity is successfully closed or not
- Add a get record element to find Slack message destinations for channel opportunities-notifications
- Add a decision element to check if the Slack message destination was found or not (from step 3)
- Add a get record element to find Slack Auth for opportunity owner
- Add a decision element to check if Slack Auth for opportunity owner was found or not (from step 5)
- Add a Text Template to construct the message body
- Add Slack: Post Message action – to post a message to a Slack channel
Step 1: Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows, then click on the New Flow.
- Select the Record-Triggered Flow option, click on Create
- Object: Opportunity
- Trigger the Flow When: A record is created or updated
- Set Entry Conditions
- Condition Requirements: None
- Optimize the Flow For Action and Related Records
- Click Done.
Step 2: Using Decision Element to Check if Opportunity is Successfully Closed or Not
- On Flow Designer, click on the + icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label; the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.StageName}
- Operator: Equals
- Value: Closed Won
- Row 1:
Step 3: Adding a Get Record Element to Find Slack Message Destination for opportunities-notifications Channel
This step aims to find the opportunities-notifications channel Id in Slack.
- On Flow Designer, below the Closed Won node, click on the +icon and select the Get Element element.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Slackv2__Message_Destination__c object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: slackv2__Channel_Name__c
- Operator: Equals
- Value: opportunities-notifications
- Click Add Condition
- Row 2:
- Field: slackv2__Channel_Type__c
- Operator: Equals
- Value: channel
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to Automatically store all fields.
- Click Done.
Step 4: Using Decision Element to Check If Slack Destination was Found or Not
Now we will use the Decision element to check the Record Variable from step 3 to find if it returns the Message Destination record for the Slack channel opportunities-notifications found or not.
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!Get_Message_Destination}
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Row 1:
- Click Done.
Step 5: Adding a Get Record Element to Find Slack Auth for Opportunity Owner
This step is optional, but we want to ensure the opportunity owner has authenticated the Salesforce app in Slack as per the requirement.
- On Flow Designer, below the Yes node, click on the +icon and select the Get Element element.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Slackv2__Slack_Auth__c object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: slackv2__User__c
- Operator: Equals
- Value: {!$Record.OwnerId}
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to Automatically store all fields.
- Click Done.
Step 6: Using Decision Element to Check If Slack Auth for Opportunity Owner was Found or Not
Now we will use the Decision element to check the Record Variable from step 5 to find if it returns the Slack Auth for Opportunity Owner found or not.
- On Flow Designer, click on the +icon and select the Decision element.
- Drag-and-drop Decision element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!Get_Slack_Auth_Opportunity_Owner}
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Row 1:
- Click Done.
Step 7: Add a Text Template to Construct Message Body
Now we’ll construct a Slack message body using the Text Template. The text template allowed you to specify the multi-line messages. You can tag a user in a Slack post by using the brackets around the @SlackuserID
, like <@SlackuserID
>.
- Under Toolbox, select Manager, then click New Resource to create a text template.
- Input the following information:
- Resource Type: Text Template
- API Name: tt_MessageBody
- Select View as Plain Text
- Body
- <@{!Get_Slack_Auth_Opportunity_Owner.slackv2__Slack_User_Id__c}> just closed a new deal. Congratulations!! 👏
- Click Done.
Step 8: Add Slack: Post Message action – to Post a Message to a Slack channel
We will use the Slack:Post Message action to send a message to a Slack channel.
- On Flow Designer, below the Found node, click on the +icon and select the Action element.
- Search and select the Slack: Post Message from the dropdown menu
- Enter a name in the Label field; the API Name will auto-populate.
- Set Input Values
- Message Destination ID: {!Get_Message_Destination.Id}
- Record ID: {!$Record.Id}
- Message: {!tt_MessageBody}
- Click Done.
In the end, Martin’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 55
- Interview Label: Post a message to a Slack Channel {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
Now onwards, if a business user updates the Opportunity Stage to Closed Won, record-triggered after-save will automatically post a message to the Slack channel.
- Navigate to the Opportunities tab and update the opportunity Pyramid Emergency Generators status to Closed Won, as shown in the following screenshot:
- Check out the opportunities-notifications Slack Channel.
Formative Assessment:
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.
“Hi, how did you get your message to be sent from a Salesforce BOT? Mine currently sends from the Salesforce Admin who set it up and we would love it to come from Salesforce instead. ” So did you rename the Slack User to Salesforce Bot? or the Salesforce Admin User to Salesforce Bot? Also how come by installing ‘Sales’ app on slack and connecting the org
could help us send message via sales app? Could you help me through this?
The Salesforce BOT is essentially an integration user. Now use “Sales Cloud for Slack” app to post via sales cloud app.
Hi Rakesh, I skipped some steps to create a flow. However, everything worked fine except each message was post twice. Is there any way to avoid it? Thanks!
Hi Rakesh,
Thanks for this guide, very useful!
For some reason I can’t see the screenshots, but my question is where do I get the object Slackv2__Slack_Auth__c ? does it come through Salesforce for Slack? The rest is super clear but I’m having troubles trying to mention people and I guess I need the salesforceuserID be mapped to the slackuserID somehow…
You have to install Salesforce for Slack app from AppExchange.
Can we hide Manage Alert button from Slack notification?
Hi Rakesh,
Thank you for this great post!
Can you elaborate more on how you are sending the messages to Slack via the Salesforce Bot? What is needed on both Slack and Salesforce?
I am only able to send via “Salesforce for Slack” app using the “Send Slack Message” action
But if using “Slack:Post Message” as you are showing here, then it’s only being sent from my user
Thanks
The Salesforce BOT is essentially an integration user. Now use “Sales Cloud for Slack” app to post via sales cloud app.
how to mention multiple users in the slack message ?
Is Salesforce BOT a Slack User and Salesforce User both ?
Yes in my case.
Hi Rakesh! Love your detailed posts – thank you for sharing!
I have a Slack post to channel set up for when a new case is created. It works great for internal users but if a community user creates a case via the Experience Cloud, the message is not posted to Slack. I’ve granted the community profile access to the Slack objects. Have you run across this before?
Thanks for reading, Deb 🙂
I haven’t tried Slack and Experience Cloud. Would you mins sharing a few screenshots of your Flow?
Hi Rakesh,I can several App’s for integrating saleforce with Slack.Which App one should use?
Follow the instructions mentioned here – https://slack.com/help/articles/227838227-Salesforce-apps-for-Slack
Hi Rakesh
Your posts are always so well detailed. I tried building this flow and everything seems to work fine, however, the @mention on the post in Slack says (or translates to) ‘Private user info’ instead of showing the @mention like ‘@dhriven’. I believe this may come down to some permission issue in Slack. Have you or anyone else perhaps encountered such an issue before?
I never encountered such an issue, as I ran it via the Slack Salesforce app. Would you mind sharing the screenshot?
Do you know of a way to get records of a slack channel for a specific opportunity or record to post to? Example: if a Sales Channel has been created for the opp with a dynamic name of “opportunity-{record.name}” and post to that specified channel?
Great post! Any idea based on what cirteria record fields are shown on the Record View in Slack? For example your msg has Close Date and Stage in there? is it customizable?
Hi, how did you get your message to be sent from a Salesforce BOT? Mine currently sends from the Salesforce Admin who set it up and we would love it to come from Salesforce instead.
Salesforce BOT is a user account. I renamed it to Salesforce BOT.
Connect the sales app in slack, and you can be then post a messages via the sales app.
Hi Rakesh!
The demonstration of your flow to slack messages was super helpful. I built a flow on a very similar note. Just one thing I am struggling to achieve is changing the sender of the Slack message. Currently the message appears to have come from me[as the Salesforce Admin and Oppty owner]. I noticed in your flow it appears to have come from SalesforceBOT. How did you configured that?
Thanks,
Rina
Is there any reason you choose to use the legacy app opposed to the new “Send Slack Message (Beta)” core action? Asking as I’ve been struggling to get the new core action to work
I was exploring different ways to send Slack messages. That’s all. Check this article on how to configure core action (beta) https://automationchampion.com/2022/05/30/create-a-slack-channel-using-flow-3/
Reach out to me if you need help.