Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, June 14
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Apex»Posting Rich Text Chatter using Apex

    Posting Rich Text Chatter using Apex

    Dhanik Lal SahniBy Dhanik Lal SahniNovember 21, 2022Updated:January 12, 2025No Comments5 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Posting Rich Text Chatter using Apex
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Salesforce Chatter is a collaboration tool that let users discuss and share information and files. We can post chatter information using apex, flow, process builder, or using API. This post will help in posting rich text chatter using Apex.

    Use Case

    User need to share cases with multiple users from case list views. We should be able to share some information along with sharing records mentioning all selected users.

    Solution:

    We can use chatter post to share infomation. We can use Post to Chatter flow action and FeedItem object to create a chatter post in flow. Both options have limitations while sending chatter posts.

    Post to Chatter action can not send rich formatted information and FeedItem object can not mention the user in the post. If we want to share the formatted post and mention users as well then we have to use a custom solution.

    Let us create a custom apex code that will share rich text content in chatter posts.

    Steps for a custom solution

    1. Create an Apex class to share the formatted post
    2. Create an Apex class to Annotate for flow
    3. Create a flow to share posts using the apex class
    4. Create List Button and Add to List Button Layout
    5. Test Functionality

    1. Create an Apex class to share the formatted post

    We can create an apex class that will post formatted chatter information. We can use global pattern matching to find HTML tags within post text. Using different segment ConnectApi classes we can format post text.

    We can use the apex class which is available at ConnectApiHelper. Create this class based on your organization’s naming guidelines.

    2. Create an Apex class to Annotate for flow

    Create another class that will invoke the above-created ConnectApiHelper. This class will be created as a flow action class. Create Invocable variables and get a list of input parameters from the flow.

    @InvocableMethod annotation allows the Flow to call the method. We can use Label and Description attributes to put metadata of the class for flow. As we can use only 1 input variable in method so we will create a custom type FlowInput.

    @InvocableVariable annotation allows the Flow to set the variables. We will create 3 variables communityId, subjectIds and postBody.

    • subjectIds – List of cases where the post will be posted.
    • postBody – Post content
    • communityId– Community Id where this will be posted. It is only required when we post on the community site.

    3. Create a flow to share posts using the apex class

    Now let us create a flow that will prepare post messages by mentioning users. We can use LWC or apex also to prepare messages but for better maintenance, use Flow. We can change the content at runtime on production but LWC and Apex have to go with the proper development cycle.

    As we have to share cases with the multiple user in chatter, we will share information with each record’s chatter. Each record will be preferred over the user’s chatter post, as all activity will be recorded in the record’s chatter activity. After user selection, a chatter post sends to each record mentioning the selected user.

    We have to do the below steps in screen Flow

    • Get Selected Record Ids
    • Use the Lookup component for User selection
    • Create a Chatter Post Message
    • Call Apex Class to send a formatted message

    a. Get Selected Record Ids

    Get selected records id from list view using standard ids variable in flow. Check out the post Post Chatter Feed Using FeedItem in Flow to get more detail on getting selected ids in flow.

    b. Use the Lookup component for User selection

    We can use the Lookup component to show user selection. We can enable multiple user selections using this component. Selected user ids are used in mentioning in the message body.

    Check out our other post Multi Select Lookup in Screen Flow to see how we can use lookup in screen flow.

    For this post, I have stored selected record ids in {!userIds} variable. It can store multiple recordIds.

    c. Create a Chatter Post Message

    create a chatter post message to send in the record post. We will use a Text Template to create a message body.

    Create Mention Users- We have to prepare all mentioned users in the format of {userid} so create an assignment variable like the below image. This assignment can be done in the loop for all selected users.

    Mention User in Flow for Posting Rich Text Chatter using Apex

    Case List Preparation: We need to add all selected cases in the list so prepare the body in the format of {record:recordid} and put that in order or unorder list like <li>{record:3012v0000016qdbAAA}</li>. Prepare a list like the below image.

    Case list for Posting Rich Text Chatter using Apex

    Merge post text: Merge all information in text template type variable in rich text format.

    Create Text Template for Posting Formatted HTML Chatter using Apex
    Posting Rich Text Chatter using Apex

    d. Call Apex Class to send a formatted message

    Call action Share Formatted Chatter Post to send formatted message to each selected case record. We will use the above-created post message postBody.

    Custom Apex Action in Flow

    Complete Flow Screenshot

    Screen Flow

    4. Create List Button and Add to List Button Layout

    Create a button to call the above-created screen flow and add that button to the list view button layout. Refer Post Chatter Feed Using FeedItem in Flow to see about this step.

    5. Test Functionality

    Now test functionality by selecting case records in the case list view. This will post a message to reach a selected record. It will also send notifications using email to all mentioned users.

    References:

    Connect API Helper

    Post Chatter Feed Using FeedItem in Flow

     Multi Select Lookup in Screen Flow

    Related Posts

    Top 10 Best Practice for Lightning Flow

    apex call from flow call flow from button call flow from list view button Chatter chatter post using apex FeedItem in apex flow flow action invocable class invocable method list view button layout notification in salesforce salesforce salesforce apex screen flow
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleOptimize Salesforce Reports and Dashboard
    Next Article Generate Topic Followers List
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni9 Mins Read

    10 Salesforce Chrome Extensions to Boost Your Productivity

    June 1, 2025
    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • Top 20 Salesforce Data Cloud Interview Questions & Answers for Admins June 5, 2025
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code analysis (3) code optimization (8) custom metadata types (5) design principle (9) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (65) lightning-combobox (5) lightning-datatable (10) lightning component (31) Lightning web component (63) lwc (52) named credential (8) news (4) optimize apex code (4) optimize apex trigger (3) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (142) salesforce apex (47) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.