Automate Slack-Channel creation using Salesforce Flows

Sombir Sheoran
7 min readAug 11, 2022

--

Automate Slack-Channel creation

On Account or Contact creation in Salesforce, automatically create a slack-channel (using Slack guidelines) as per the name of the Account or Contact Last Name. In this post, we would be working with an Account scenario.

Expected Output from this post: Automate Slack-Channel creation using Salesforce Flows

The Problem Statement

Let’s consider a business scenario

  • Your business requires creating a new channel in Slack, every time an Account with field values: Active= Yes, Rating = Hot and Annual Revenue > $1mn is created in Salesforce, so your Account team members can collaborate with each other and there is no need to create the channel manually every time it satisfies the business criteria in Salesforce. It would save a lot of manual efforts for the business and the matching cost.💰
  • Only if the above conditions are satisfied for the new account, we have to create a slack channel with a name getting generated dynamically.
  • Rules: Slack channel name format:{your-org-prefix} + {first-30-characters-from-account-name} + {account-rating}
  • Note: Slack channel names cannot exceed the limit of 80 characters

Let’s first understand, What a Slack Channel really is?

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

The pre-requisites

  1. Salesforce for Slack app integration set-up must be ready as explained in detail in another post.
  2. At least one** of the following Slack directory apps, must be installed and configured in Slack & Salesforce for the proper functioning of the use case.

** Since our problem Statement involves the creation of the Slack channel based on Account creation, Sales Cloud for Slack configuration is enough for this module. In case you have a business requirement based on any Service cloud object, then Service Cloud for Slack must be installed and configured in the Slack current workspace.

Sales and Service Cloud app for Slack current workspace

The Use Case Implementation

  • We would be creating an after-save Record-Triggered Flow on the Account standard object.
Record Triggered Flow
Make sure to Select the Above Check box, to take an after-save Async action

Note: Above check-box selection helps to run the Flow in two paths: One in Sync (Runs immediately as soon as record is Saved) and second in Async (Runs Asychronously after record is saved to database, independently to call any external system or services.)

  • Make sure that, all entry criteria conditions are met, as given in the problem statement: Active= Yes and Rating = Hot is created with Annual Revenue > $1mn so that only the specific Account records meeting these conditions, go for Slack channel creation.
Record Trigger Flow on Account: Async Checkbox Checked
  • Click Done, our Flow should look like below with our 3 conditions:
Account Flow — Initial look

Slack channel name format logic:(lower case with — )
{your-org-prefix} + {first-30-characters-from-account-name} + {account-rating}

Let’s store the {your-org-prefix} in a Custom Label [api: Slack_Channel_Prefix] in Salesforce, to make it configurable.

Custom Label to store {your-org-prefix}
  • Now, make a new Flow resource of formula type (Text) as below and click Done. Slack channel names are always in lower case with hyphen(—) characters in between different words of the name. Formula text should look like the below: where Slack_Channel_Prefix is the custom label.

{!$Label.Slack_Channel_Prefix} + SUBSTITUTE(LOWER(LEFT({!$Record.Name}, 30)), “ “, “-”) + “-”+ LOWER(TEXT({!$Record.Rating}))

  • Since the Rating on the Account object is a PickList field, so using {!$Record.Rating} in the formula would give an error. We need to get the text value for it in lower case.
Flow resource: slackChannelNameDynamic, to be used in later steps
  • Before we go ahead, make sure that you’re connected to the right Slack workspace, in our case: salesforce-slack-talks
salesforce-slack-talks: Slack Workspace Name
  • On the Run Asynchronously path, click + to add a new Flow action
Add New Flow action
Type and Search for: Create Slack Channel
  • Since we need to call an external System (Slack), we would call the: Flow Core Actions for Slack: Create Slack Channel which needs below main inputs:

Set Connection Values for Slack

  1. Slack app: Required: The Slack app that executes the action. Only Slack apps that are installed for the org are available. The input value evaluates to the Slack app ID. In our case, we select: Sales Cloud for Slack
  2. Slack Workspace ID: Required. The Slack workspace where the Slack app is installed. Select a value or resource. The input value evaluates to the Slack workspace ID. In the below URL, T03SCBUGVEU is the ID.
Slack Workspace ID

3. Execute Action As The entity that executes the action. Valid values are:

a. Slack App: Execute the action as the Slack app that you selected in the Slack App field. This is the default value. The Slack app must be a member of the conversation to execute the action on.

b. User Who Runs the Flow: Execute the action as the user who runs the flow. The user can execute the action only when the flow runs in the user context. If the flow runs in the system context, it’s executed by the Slack app.
The user must be a member of the conversation to execute the action on.

Set Slack Channel Details

4. Slack Channel Name: Required: Use the Flow resource {slackChannelNameDynamic} which generated the channel name on the fly.

5. Channel Type: Public / Private or / Resource, Default is Public.

6. Slack Workspace ID for Channel: Indicates whether to associate the new channel with a different workspace ID than the workspace ID of the Slack app. If you turn this option on, select a value or resource.

Store Output Values

7. Slack Channel ID: The ID of the new channel. In case we need to take any action, say: posting a message in the newly created channel, then we can take this as output and store it in a resource variable. Store in flow text resource {newSlackChannelID}

Once all these values are set in the Create a Slack Channel Automatically, it should look as below:

Create a Slack Channel Automatically
  • Click Done. The Final flow must look like the below.
  • Save and Activate the flow, after giving it some logical name.
Flow: Automate Slack-Channel creation for New Accounts

This completes your development. Now it’s time to test the same.

Validating your flow logic

  • Let’s go to the Sales app > Account tab in Salesforce and create a test account.
  • Make sure for the new account, Rating = Hot, Active = Yes, and Annual Revenue >$1mn, give it a meaningful name, and Save the record.
New Account in Salesforce with valid entry criteria
New Account records pushed to Slack

Want to validate your new Slack-channel record?

Note: The slack channel creation step in the flow was on the Async path, possibility is that it might take some time in order to execute that step and hence, channel creation in Slack might reflect after some time.

  • Tip💁: By default, you’re not a member of the newly created Slack Channel. As an add-on, you might try to add one more Flow step to call the ‘Invite Users to Slack Channel’ Flow — Slack action and then join the channel as per the invite.
  • In case you don’t find the newly created Slack channel under your channel. Go to the next step:
Slack-app channels
  • Click Channel > + icon near 3 dots : Browse channels 🔍
+ Browser channels
  • Since your Salesforce account record name was: “Demo Salesforce 2 Slack Channel Creation”, try typing the initial keywords in lower case appended with a hyphen(-), as “demo-salesforce-2” and hit Enter key.

Wow, you see your channel now, Congratulations🎉

Searching the new channel in Slack under All Channels
  • Just Select the Channel and Join as needed. There is no limit to collaboration in Slack now for your newly created channel.
New Slack channel in action

Congratulations, it confirms that “Automate Slack-Channel creation using Salesforce Flows” is working perfectly.❤️

References:

Developer details:

Please reach out to me for any suggestions or feedback. Would love to hear them❤ If you loved this post, please applaud at the end of this post with a 👏

--

--

Sombir Sheoran
Sombir Sheoran

Written by Sombir Sheoran

I'm a Certified Salesforce Consultant ☁️ who loves to write technical blogs, which help simplify Salesforce solutions. Follow to learn more ✨⚡

Responses (1)