Streamlining Communication and Collaboration: Integrating Salesforce with Slack

In today’s fast-paced business environment, effective communication and collaboration are paramount to success. Companies are constantly on the lookout for innovative ways to bridge the gap between their various platforms and tools, ensuring seamless information flow. One such powerful integration is between Salesforce, the leading customer relationship management (CRM) platform, and Slack, a popular team communication app. In this blog post, we’ll dive into a specific use case that highlights the potential of this integration: notifying Slack users about important updates within Salesforce using the @mention chatter feed feature.

The Use Case: Salesforce Integration with Slack App 

Imagine you’re a sales professional working with Salesforce to manage your customer interactions, deals, and opportunities. On the other hand, your team relies on Slack for real-time communication and collaboration. Now, consider a scenario where you want to keep your team updated about the status of deals in Salesforce without having to switch back and forth between platforms. This is where the integration between Salesforce and Slack comes to the rescue.

Seamless @Mentions via Chatter Posts

Salesforce offers a robust feature called Chatter, which allows users to collaborate and communicate within the CRM platform. You can use Chatter to make posts and comments related to various records, including deals, leads, and contacts. With the integration set up, you can now leverage the @mention functionality in Chatter posts to bring the attention of specific team members to important updates.

For instance, let’s say you’ve just closed a deal that was being managed in Salesforce. Instead of sending separate emails or messages to your team members, you can create a Chatter post and @mention relevant users. For example, you can write a post like, “@gaurav Hii, we have a big deal please close asap !”  This simple action ensures that Gaurav receives a notification about the update.

Instant Notifications on Slack

Here’s where the integration’s magic truly shines. As soon as you hit the “Post” button on your Chatter update, the integration between Salesforce and Slack springs into action. The mentioned user, in this case, Gaurav, will receive a notification directly on Slack. This means that Gaurav doesn’t need to keep checking Salesforce for updates; the information comes to him in a platform he’s actively engaged with.

Setting Up the Integration

Setting up this integration doesn’t have to be a daunting task. Both Salesforce and Slack offer user-friendly methods to connect the two platforms. By using Salesforce’s AppExchange and Slack’s App Directory, you can find pre-built integrations or connect the platforms using APIs if you require more customized functionality. Follow the step-by-step guides provided by both platforms to ensure a smooth and secure integration process.

In Conclusion

The integration between Salesforce and Slack offers a powerful solution for enhancing communication and collaboration within your organization. By harnessing the capabilities of Chatter’s @mention feature and the instant notification system in Slack, you can keep your team members informed about important updates without any friction. This streamlined process not only saves time but also ensures that everyone is on the same page when it comes to crucial deals and customer interactions. So, whether you’re a sales professional, a project manager, or anyone looking to optimize their workflow, consider integrating Salesforce with Slack to experience a new level of efficiency and connectivity.

Step 1: Install and Authorize

The first step in the integration process is to install the Slack app and grant the necessary permissions. Follow these steps:

  • Install Slack App: Head over to your Salesforce account’s AppExchange and search for the Slack integration app.or you can click the link https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FnD9mUAF. Once you’ve found it, click on the “Get It Now” button and follow the installation instructions. This will ensure the app is added to your Salesforce instance.
  • Authorize Slack App: After installation, open the Slack app from your Salesforce account. You’ll be prompted to authorize the app to access your Slack workspace. This step is crucial for enabling data sharing between the two platforms. Click “Authorize” and follow the authentication steps provided.

Step 2: Create a Custom Field

To effectively link the Slack user IDs with Salesforce records, you’ll need to create a custom field in the User object. Here’s how:

  • Navigate to Object Manager: From your Salesforce homepage, click on the “App Launcher” (grid icon) and search for “Object Manager.” Select “User” from the list of objects.
  • Create a Custom Field: In the User object, click on “Fields & Relationships” and then “New.” Choose the data type as “Text” and give the field a meaningful name like “Slack ID.”
  • Field Properties: Set the field properties according to your preferences. You can choose whether the field should be visible to all users, required, or unique.

Step 3: Authorize your workspace

Click 9 dots in your salesforce org  search the slack setup app click and authorize to your workspace.

Step 4: Click the automatic configuration

Click the new Message Destination button A modal will appear to provide the necessary information.

Like MessageDestination Name, Slack workspace, Slack channel, or person Name, And Hit save.

Step 4: Mapping IDs

Now that you have the necessary components in place, it’s time to establish a connection between the Slack user IDs and Salesforce records:

  • Gather Slack User IDs: In your Slack app, find the user IDs that correspond to each user in your Salesforce organization. These IDs are unique identifiers within Slack and will help establish the link.
  • Copy the message destinationId and Update Salesforce User Records: Go to the user profiles in Salesforce one by one. In the newly created “Slack ID” field, input the corresponding Slack user ID. This step effectively maps each user’s Salesforce profile with their Slack identity.

Now Create a Record-Trigger flow  To Feed Item Object  

Follow these steps to create a flow:

Final will Look like this

/*
 *	Author Name: Gaurav Kumar
	Date: 30-Aug-2023
	Purpose: Purpose for the method to get the chatter post text items,and mention user 
 * 
*/
public class feedinvocable {
    
    
    @InvocableMethod(Label='get the feed items')
    public static List<List<Id>> getfeed(List<FeedItem> lstfeed){
        List<List<Id>> lstId = new List<List<Id>>();
        
        String communityId = null;
        List<Id> mentionUser =new List<Id>(); 
        try{
            for(FeedItem fd : lstfeed){
            ConnectApi.FeedElement feedItem = ConnectApi.ChatterFeeds.getFeedElement(communityId, fd.id);
            List<ConnectApi.MessageSegment> messageSegments = feedItem.body.messageSegments;
            for (ConnectApi.MessageSegment messageSegment : messageSegments) {
                if (messageSegment instanceof ConnectApi.MentionSegment) {
                    
                    ConnectApi.MentionSegment mentionSegment = (ConnectApi.MentionSegment) messageSegment;
                    
                    System.debug('Mentioned user name: ' + mentionSegment.name);
                    System.debug('Mentioned user id: ' + mentionSegment.record.id);
                    mentionUser.add(mentionSegment.record.id);
                }
                
            }
                lstId.add(mentionUser);
            
        }
        return lstId;
        }catch(Exception e){
            System.debug('exception occuurred is '+e.getMessage());
            System.debug('exception occuurred is '+e.getLineNumber());
            return null;
            
        }
  
    }
}

Overview

The feedinvocable class is an Apex class in Salesforce that contains an invocable method used to extract mentioned user IDs from Chatter feed items.

Invocable Method: getfeed

The getfeed method is an invocable method within the feedinvocable class. It takes a list of FeedItem objects as input and returns a list of lists of user IDs.

Signature

public static List<List<Id>> getfeed(List<FeedItem> lstfeed)

Parameters

  • lstfeed (Type: List<FeedItem>) – A list of FeedItem objects representing Chatter feed items from which mentioned user IDs need to be extracted.

Return Value

  • Type: List<List<Id>> – A list of lists of user IDs. Each inner list corresponds to the user IDs mentioned in a particular feed item.

Description

The getfeed method iterates through the input list of FeedItem objects. For each FeedItem, it retrieves the associated Chatter feed element using the ConnectApi.ChatterFeeds.getFeedElement method. It then extracts mentioned user IDs from the feed element’s body message segments.

The method specifically looks for ConnectApi.MentionSegment instances within the message segments. For each mention found, the mentioned user’s ID is extracted and added to the mentionUser list. After processing all message segments in a feed item, the mentionUser list is added to the lstId list.

Finally, the lstId list, containing lists of mentioned user IDs, is returned

If an exception occurs during the process, the method catches the exception, logs relevant debug information (error message and line number), and returns null.

Conclusion

The feedinvocable class provides a convenient way to extract mentioned user IDs from Chatter feed items using the getfeed invocable method. It can be utilized in Salesforce applications to enhance collaboration and communication among users