Auto Post a Message to Chatter When an Event is Created

Advertisements

Last Updated on April 6, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

How do you automatically Post a message to the Chatter Group message when a user creates an event?

In Salesforce, Chatter Group represents the group of people. It’s a great way to boost collaboration in your organization. You can add unlimited members to a Chatter Group, but a user can only join a maximum of 100 Groups. In the article Post Opportunity details to a Chatter GroupI had discussed how to post Opportunity closed information to a Chatter Group using the Flow. In the current article, we will discuss how to post a message to the Chatter Group using the Salesforce Flow. 

Objectives:

After reading this blog, you’ll be able to: 

  • Use After-save Record-Triggered Flow to Post a message to Chatter
  • Use Get element to avoid hard coding of Id
  • Use the Decision element to validate the get records outcome 
  • Auto-create a Post to Chatter when an Event is created

Business Use case

Brandon Schaefer is working as a System Administrator at Gurukul on Cloud (GoC). His organization wants to post a message to the Chatter Group UC Internal Announcements, whenever an event is created for the public calendar Universal Container Conference Rooms.

Automation Champion Approach (I-do):

Public Calendars and resources are for managing group activities or shared resources. By using Public Calendars, a group of people can track events of interest to all of them (e.g., Sales events, weekly knowledge sharing sessions, or training classes) or schedule a common activity (e.g., a team vacation calendar).
 
For example, with resource calendars, multiple people can coordinate their usage of a shared resource such as a conference room, etc. An organization can create an unlimited number of calendars.
 
Before proceeding, ahead, understand the CollaborationGroup object in Salesforce. It represents a Chatter group.

While this can be solved using various automation tools like Apex Trigger, or Flow, we will use After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario. 

Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understand it. Let’s begin building this automation process.

Guided Practice (We-do):

There are 3 steps to solve Brandon’s business requirement using Record-Triggered Flow. We must:

  1. Create a chatter group
  2. Create a public calendar 
  3. Salesforce flow
    1. Define flow properties for record-triggered flow
    2. Add a Text Template to construct the chatter post message body
    3. Create a formula to determine whether the event is created or updated
    4. Add a decision element to check if an event is owned by a public calendar 
    5. Add a get records element to find the chatter group details (UC Internal Announcements)
    6. Add a decision element to check if the chatter group was found or not 
    7. Add action post to chatter – to post a message to the chatter group 

Step 1: Create a Chatter Group

  1. Navigate to App Launcher and click on the Groups.
  2. Clicks on the New button
  3. Name the Group and make sure to select the Private Access Type.
  4. Click Save.

Step 2: Create a Public Calendar Universal Container Conference Rooms

  1. Click Setup.
  2. In the Quick Find box, type Public Calendars and Resources.
  3. Clicks on the New button
  4. Name the Calendar and make sure to select the Active checkbox.
  5. Click Save.

Step 3.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 and configure the flow as follows:
    1. Object: Event
    2. Trigger the 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 3.2: Add a Text Template to Construct Chatter Post Message 

 Now we’ll create an email template using the Text Template. The text template allowed you to specify the multi-line messages. It also allows you to use HTML code.

  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. An event is created for the public calendar “Universal Container Conference Rooms” click on the link below to learn more about it.
      2. URL > https://rakeshistom1234-dev-ed.lightning.force.com/{!$Record.Id}
  3. Click Done.

Step 3.3: Formula to Determine Whether the Event is Created or Updated

  1. Under Toolbox, select Manager, then click New Resource to determine whether the record is created or updated. 
  2. Input the following information:
    1. Resource Type: Formula
    2. API Name: forB_IsNew
    3. Data Type: Boolean
    4. Formula: IsNew()
  3. Click Done.

Step 3.4: Using Decision Element to Check if Event is Owned by Public Calendar 

Now we will use the Decision element to check if the event is owned by the public calendar Universal Container Conference Rooms.  

  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.Owner:Calendar.Name}
      2. Operator: Equals
      3. Value: Universal Container Conference Rooms
    2. Click Add Condition
    3. Row 2:
      1. Resource: {!forB_IsNew}
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 3.5: Adding a Get Record Element to Find Chatter Group – UC Internal Announcements

The next step is to use the Get Records element to find chatter group UC Internal Announcements details. 

  1. On Flow Designer, below the Yes node, click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Group (CollaborationGroup) object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: Name
      2. Operator: Equals
      3. Value: UC Internal Announcements
  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 3.6: Using Decision Element to Check If Chatter Group was Found or Not 

Now we will use the Decision element to check the Record Variable from step 3.5 to find if it returns the Chatter group UC Internal Announcements 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_Chatter_Group}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 3.7: Add Post to Chatter Action to Post a Message to Chatter Group

Now we will use the Post to Chatter static action to post a message to chatter group UC Internal Announcements.

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

In the end, Brandon’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: 54
  5. Interview Label: Post a Message to Chatter Group {!$Flow.CurrentDateTime}
  6. Click Save

Almost there! Once everything looks good, click the Activate button.

Proof of Concept

Now onwards, if a user creates an event for the public calendar Universal Container Conference Rooms, then the Record-triggered flow will automatically post a message in the Chatter group UC Internal Announcements. It’s time to test out the process.

  1. Create a new event on the Public calendar Universal Container Conference Rooms 
    1. Click on the App Launcher
    2. In the Search Apps and items box, type Calendar and click it.
    3. Add a new event by clicking a timeslot in the calendar. 
    4. For the Assigned To field, select Universal Container Conference Rooms.
    5. Fill in the remaining details for the event like the screenshot below, then click Save.
  2. Check out the Chatter Group, UC Internal Announcements. The following post will be automatically added to the group wall.

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)

13 thoughts on “Auto Post a Message to Chatter When an Event is Created

  1. @rakesh Any way to modularize this across sandbox refreshes? I’ve found even if a Group exists in SB with the same name as in production, I have to deactivate my PBs, and reactivate in sandbox, selecting the desired group.

    I’ve looked through some of JenWLee’s blogs, but can’t think of a custom label, custom setting, or custom metadata way to get Process Builder to use the native Post-To-Chatter action to a Group, when I want to look up the group from 1 of these. Am I missing something? Do you get PB in Sandbox to post to group effortlessly after refreshes, or do you have to modify each PB?

    1. Rakesh Gupta – Mumbai – 9x Salesforce MVP | Senior Solution Architect | 8x Author | 5x Dreamforce Speaker | Salesforce Coach | Co-host of AutomationHour.com and AppXchangeHour.Com

      I never encountered such scenario. But my suggestion would use Custom Label (to store Chatter Group Id) and refer this to process builder.

      P.S.:- looks like your comment is marked as SPAM by WordPress (i don’t have any idea, how and why).

  2. Hi Rakesh

    I’m trying to via process builder create a chatter post onto the Opportunity record if certain products are contained in the Opp product.

    I think I need what you refer to as Record Chatter Feed below, but the only 2 options I see are post to User or Chatter Group, how do you make this third option accessible from Process Builder please?

    Thanks
    Nic

    Our final task is to add an Immediate action to the Process. Click on Add Action (Under Immediate actions) and select the type of action to create (In our case Post to Chatter) , enter the Name Post to Chatter. This action allows you to post a message on User Profile or Chatter Group or on Record Chatter Feed. In this case select Chatter Group UC Internal Announcement, as shown in the following screenshot

    1. 1) To enable “This Record” option under post to chatter action, make sure that you have enabled feed tracking for that particular object.
      2) In your scenario, you are creating a PB on Opportunity Product and want to post a message to opportunity record. To achieve this, you have to use both Process and Flow.

      1. It appears the process builder wont link at all to community, none of the partner community groups appear in the selection either

        POST TO CHATTER: myRule_1_A2
        Inputs:
        text = Below are a few steps to get you up to speed with our new system. 1.Search Q&A for Onboarding- Post a message. 2. Search Q&A forOnboarding- Responding in a post Welcome to TSV Connect. 3. Search Q&A forOnboarding- How to like a post Welcome to TSV Connect. 4. Search Q&A forOnboarding- Share a post titled Welcome to TSV Connect. 5. Search Q&A forOnboarding- How to @mention on Welcome to TSV Connect. 6. Search Q&A forOnboarding-How to find and join groups.
        type = USER
        subjectNameOrId = {!myVariable_current.Id} (005U00000066yFrIAI)

        Error Occurred: The record for this post was deleted.

        1. Hi Onttu,

          Its a pretty late reply but thought to answer anyhow – the issue is due to process builder deployed from one sandbox to another, it retains the chatter group salesforce id from the source org even when activated post deployment in target org. You will have to delete the post to chatter action in target and recreate it once more as it will now fetch the target org’s chatter group id.

          Regards,
          M

  3. how did you made the 15digits to 18 digits ID , i am applying the same thing but i believe this 3additional number in reference id is not allowing me to trigger the rule
    please assist

Leave a ReplyCancel 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

Exit mobile version
%%footer%%