Send A Direct Slack Message Using Flow

Send A Direct Slack Message Using Flow

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? 
Slack is a messaging app for businesses that connects people to the information they need. Its workspaces allow you to organize communications by channels for group discussions and allow for private messages to share information, files, and more all in one place. Plus, Slack integrates with a host of other apps so you can manage your entire workflow through one platform.

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:

  1. The first step is to complete Salesforce for Slack integration.
  2. 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:

  1. Define flow properties for record-triggered flow
  2. Add a decision element to check if the account owner has changed 
  3. Add a get record element to find the Slack Id of the account owner to send a direct message  
  4. Add a decision element to check if the Slack message destination was found or not (from step 3) 
  5. Add a Text Template to construct the message body
  6. Add Slack: Post Message action – to send a direct message to a Slack user  

Step 1: Define Flow Properties

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows, then click on the New Flow.
  4. Select the Record-Triggered Flow option, click on Create 
    1. Object: Account
    2. Trigger the Flow When: A record is created or updated
    3. Set Entry Conditions
      1. Condition Requirements: None
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 2: Using Decision Element to Check if Account Owner Has Changed

Now we will use the Decision element to check if account owner has changed or not.
  1. On Flow Designer, click on the + icon and select the Decision element. 
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label; the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.OwnerId}
      2. Operator: Is Changed 
      3. Value: {!$GlobalConstant.True}

Step 3: Adding a Get Record Element to Find Slack Id for the New Account Owner to Send a Direct Message

  1. On Flow Designer, below the Yes node, click on the +icon and select the Get Element element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Slackv2__Message_Destination__c object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: slackv2__Channel_Name__c
      2. Operator: Starts With
      3. Value: {!$Record.Owner.FirstName}
    2. Click Add Condition
    3. Row 2:
      1. Field: slackv2__Channel_Name__c
      2. Operator: Ends With
      3. Value: {!$Record.Owner.LastName}
    4. Click Add Condition
    5. Row 3:
      1. Field: slackv2__Channel_Type__c
      2. Operator: Equals
      3. Value: user
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. 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. 

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Get_Message_Destination}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  5. 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>. 

  1. Under Toolbox, select Manager, then click New Resource to create a text template. 
  2. Input the following information: 
    1. Resource Type: Text Template
    2. API Name: textT_MessageBody
    3. Select View as Plain Text
    4. Body 
      1. Congratulations <@{!Get_Message_Destination.slackv2__Channel_Id__c}> a new account 💰 has been assigned to you.
  3. 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. 

  1. On Flow Designer, below the Found node, click on the +icon and select the Action element.
  2. Search and select the Slack: Post Message from the dropdown menu
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Set Input Values
    1. Message Destination ID: {!Get_Message_Destination.Id}
    2. Record ID: {!$Record.Id}
    3. Message: {!textT_MessageBody}
  5. Click Done.

In the end, Martin’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label; the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 55
  5. Interview Label: Send A Direct Slack Message {!$Flow.CurrentDateTime}
  6. 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.

  1. Navigate to the Account tab and update the account Pyramid Construction Inc. owner to Nathan Gilmore, as shown in the following screenshot:
  2. 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.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!
Preferred Timing(required)

23 thoughts on “Send A Direct Slack Message Using Flow

  1. Hello, I’m having issues when a user have a space in their name. The mention works if the user just has “name” as the Slack User Name. However, if a user has “first” “last” as their slack user, the mention doesn’t work. I noticed that your user has a space, but I don’t know how you made it work.

  2. 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?

    1. 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

  3. 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.”

    1. 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?

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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?

  9. 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.

  10. 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!

  11. 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

    1. 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.

  12. 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.

    1. 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.

  13. 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading