Send A Direct Slack Message Using Flow

Send A Direct Slack Message Using Flow

Last Updated on May 30, 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 Opportunity Flow When: A record is created or updated
    3. Set Entry Criteria
      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!

2 thoughts on “Send A Direct Slack Message Using Flow

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