Last Updated on December 7, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
- How do you send a direct message to the account owner on Slack via Salesforce Flow?
I have written a few articles on Slack and Flow. Why not check them out while you are at it?
Objectives:
After reading this blog, you’ll be able to:
- Understand Slack direct messages
- Understand Message Destination object
- Use get records to avoid hard coding of Id
- @Mention slack user in a post
- Send a direct message to a Slack user using the record-triggered flow
- 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). GoC wants to send a direct message to the account owner on Slack when an account is assigned to them.
- Message – Congratulations <tag account owner> a new account 💰 has been assigned to you.
Pre-requisites:
- The first step is to complete Salesforce for Slack integration.
- The next step is to set up message destinations. Especially for account owner Nathan Gilmore for current business sceanrio.
Understand Direct Messages
Direct messages (DMs) are smaller conversations in Slack that happen outside of channels. DMs work well for one-off conversations that don’t require an entire channel of people to weigh in, like if you wanted to ask a teammate to reschedule a meeting.
Messages can be more than just words. You can select the icons below the message field to add attachments, formatting, and more as you’re typing your message.
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. |
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 6 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 the account owner has changed
- Add a get record element to find the Slack Id of the account owner to send a direct message
- Add a decision element to check if the Slack message destination was found or not (from step 3)
- Add a Text Template to construct the message body
- Add Slack: Post Message action – to send a direct message to a Slack user
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: Account
- 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 Account Owner Has Changed
- 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.OwnerId}
- Operator: Is Changed
- Value: {!$GlobalConstant.True}
- Row 1:
Step 3: Adding a Get Record Element to Find Slack Id for the New Account Owner to Send a Direct Message
- 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__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: Starts With
- Value: {!$Record.Owner.FirstName}
- Click Add Condition
- Row 2:
- Field: slackv2__Channel_Name__c
- Operator: Ends With
- Value: {!$Record.Owner.LastName}
- Field: slackv2__Channel_Name__c
- Click Add Condition
- Row 3:
- Field: slackv2__Channel_Type__c
- Operator: Equals
- Value: user
- 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 the Slack Message Destination was Found or Not
Now we will use the Decision element to check the Record Variable from step 3 to check, if it returns the Message Destination record for account owner 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: Add a Text Template to Construct Message Body
Now we’ll construct 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: textT_MessageBody
- Select View as Plain Text
- Body
- Congratulations <@{!Get_Message_Destination.slackv2__Channel_Id__c}> a new account 💰 has been assigned to you.
- Click Done.
Step 6: Add Slack: Post Message action – to Send a Direct Message to Account Owner on Slack
Now we will use the Slack:Post Message action to send a direct message to account owner on Slack.
- 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: {!textT_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: Send A Direct Slack Message {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
Now onwards, if a business user reassigns an account a user, record-triggered after-save will automatically send a direct message to the new owner on Slack.
- Navigate to the Account tab and update the account Pyramid Construction Inc. owner to Nathan Gilmore, as shown in the following screenshot:
- Now login to Slack via Nathan’s account and check out the direct message received from Salesforce BOT.
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.
I want to send direct message to multiple users using Salesforce to Slack in Salesforce Flow but as this moment it only allows single channel. Does anyone of you guys know how to send multiple direct message in Flow?
I apologize, it’s been some time since I last worked on Slack automation. However, you might want to consider an approach similar to this when constructing your message body.
Congratulations <@{!Get_Message_Destination.slackv2__Channel_Id__c}> a new account 💰 has been assigned to you.
<@{!Get_Message_Destination_2.slackv2__Channel_Id__c}> //another user reference
Hello,
My message is well sent but from my user.
What should I do for it to be sent by Salesforce Bot?
Thanks
Salesforce BOT is nothing but a Integration user. Now use “Sales Cloud for Slack” app to post via sales cloud app.
Hi Rakesh, I’m getting the same error as Tomas despite also having connected and disconnected the apps. Do you have any insights into how Tomas fixed this?
“Error Occurred: The Salesforce user isn’t connected to Slack. Reinstall the app in Slack, or reconnect the app’s Salesforce user to Slack, and try again.”
I haven’t used the Slack integration for some time. Please ensure that the user is connected to your Slack Organization. Would it be possible for you to join the my office hour this weekend (Saturday) so that we can deeper into this issue if you still require help?
Hi Rakesh,
I am also getting the “The Salesforce user isn’t connected to Slack. Reinstall the app in Slack, or reconnect the app’s Salesforce user to Slack, and try again.” error even after deleting and reconfiguring the app in Slack. Was there another workaround for that? Thanks.
For this error:
Error Occurred: The Salesforce user isn’t connected to Slack. Reinstall the app in Slack, or reconnect the app’s Salesforce user to Slack, and try again.
Have you found a solution? I’m also getting that. I think the Slack Integration User and the System Connections user in Slack Setup (App Manager) need to be the same. Will update if it solves the issue.
I have the message mentioned in prev commeins:
The Salesforce user isn’t connected to Slack. Reinstall the app in Slack, or reconnect the app’s Salesforce user to Slack, and try again.
Well… for those of you having troubles with the “Error Occurred: The Salesforce user isn’t connected to Slack. Reinstall the app in Slack, or reconnect the app’s Salesforce user to Slack, and try again.” ===> the workaround that is to go to Personal settings (Click your profile pic in Salesforce) => Settings. Then in the quick search type “Slack” and then you’ll see the “Slack user mapping” or something like that option. Click there, if your Sales/Service app for Slack is connected, you’ll see some letters and numbers as your user mapping. To the right you’ll see an arrow that shows up a dropdown menu, click “Delete”. Then you’ll have to go to Slack and connect the app you were using.
Hi Rakesh;
I have this working perfectly but the Direct Message always sends as me?! How in your screen grabs have you got this to send as a bot?
Hi Rakesh! Long Time Fan, First Time Posting!
I want to edit the slack message to remove all the salesforce account detail that gets appended to the end. Do you know if its possible? To clarify: If I take the message you showed in Slack above:
Congratulations a new account 💰 has been assigned to you.
In slack, I just want that text from the text template and nothing else.
That means a lot, Nino! Thank you 🙂
I was not able to find any way to remove/customize it using clicks. Let me know if you find a solution.
Hi Rakesh!
I’m getting an error when trying to send the message. The flow works just fine all the way but when it’s time to send the message I get this error:
Error Occurred: The Salesforce user isn’t connected to Slack. Reinstall the app in Slack, or reconnect the app’s Salesforce user to Slack, and try again.
I have my account Salesforce account connected to my Slack account and I even deleted the connection and reconnected again.
Have you ever seen an error like this?
Thanks!
Please let me know if you still need help; I will be happy to help you.
Same Q as Crystal: I tested using public images from static resources even stored an image as an externally available document, no luck posting slack messages with embedded images from a text template
Hold on, no need to upload a file or anything.
Simply click in the text field for that app and press Command-Control-Space simultaneously to bring up the emoji picker on Mac and select an emoji.
Unsure of how you got the emoji image into the message. I’m recreating steps for other messaging and would like to input different emojis.
Hold on, no need to upload a file or anything.
Simply click in the text field for that app and press Command-Control-Space simultaneously to bring up the emoji picker on Mac and select an emoji.
How have you gotten around the use case of a customer submitting a comment via the communities/experience site and having that event trigger a slack message to the case owner? The triggering event in Salesforce must be from a user that has both Slack and Salesforce access which a customer community user profile would not provide.