Out of Office Notification For Chatter Post

Out of Office Notification For Chatter Post

Last Updated on February 10, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

How to set up an out-of-office message for a chatter post? 

Out of Office messages are automatic email replies that go out to colleagues, customers, and clients when you are away from work. You can do these settings in your email account, but there are no such settings available in Salesforce. There are a few apps available on AppExchange for this purpose. In this article, we will create automation that allows users to set up an out-of-office message for chatter posts. 

 Objectives:

After reading this blog post, you will be able to understand:

  • When should you use Before-save vs after-save record-triggered flow?
  • Use a Decision element to find – record collection variable contains a record or not
  • Use After-save Record-Triggered Flow to create records (Bulk safe) 

Business Use case

Corey Eridon is working as a System Administrator at Universal Containers (UC). He has received a new requirement to implement Out of Office notification for Chatter post. It means if a user is out of the office and every time someone mentions him on a Chatter post (TextPost or LinkPost) then auto post an automatic out-of-office comment. Similar to the following screenshot:

Automation Champion Approach (I-do):

There are multiple ways to solve the above business requirement. You can either use Apex trigger, Salesforce Flow, Process Builder, and more. To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario. 

Before proceeding ahead, you have to understand the FeedComment object. It represents an entry in the feed, such as changes in a record feed, including text posts, link posts, and content posts.

Field Name Details
CommentBody The text in the comment. group.
CommentType The type of comment:
  • ContentComment—an uploaded file on a comment
  • TextComment—a direct text entry on a comment
FeedItemId The Id of the feed item containing the comment.
CreatedById The Id of the user who added this item to the feed. 

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 2 steps to solve Corey’s business requirement using After-save Record-Triggered Flow. We must:

  1. Create a few custom fields on the user object
  2. Salesforce Flow
    1. Define flow properties for record-triggered flow
    2. Add a get records element to find all out of office messages 
    3. Add a decision element to check if out of office message exist 
    4. Loop element to extract records from the record collection variable (step 2.2)
    5. Add a decision element to check if the loop variable contains names mentioned in the chatter post
    6. Add an assignment element to construct (record variable) the out of office comment
    7. Add an assignment element to add all comments into a record collection variable 
    8. Add a create records element to add comments to post (bulk safe) 

Step 1: Creating Few Custom Fields on the User object 

First of all, we will create the following fields on the user object to store out of office details.

Field Name Data Type
Out of office Start Date Date
Out of office End Date Date
Out of office Message TextArea
  1. Click Setup.
  2. In the Object Manager, type User.
  3. Select Fields & Relationships, then click New.
  4. Select Date as Data Type, then click Next.
  5. Enter Field Label and click the tab key, the API Name will populate. 
  6. As a best practice, always input a description
  7. Set the Field-level Security for the profiles, make sure to set this field as read-write. 
  8. Add this field to Page Layout.
  9. Click Save.

Step 2.1: Salesforce Flow – Define Flow Properties 

As we have a requirement of creating a record in (FeedComment) when a chatter post is created and it has a user tagged who is currently out of office. This is why we have to use the After-save flow on FeedItem.

  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 and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
    2. Trigger the Flow When: A record is created
    3. Run Flow: After the record is saved
    4. Object: Feed Item
  5. Select Any Condition Are Met (OR)
  6. Set Conditions
    1. Row 1
      1. Field: FeedItem | Type
      2. Operator: Equals
      3. Value: TextPost
    2. Click Add Condition
    3. Row 2
      1. Field: FeedItem | Type
      2. Operator: Equals
      3. Value: LinkPost
  7. Click Done.

Step 2.2: Salesforce Flow – Adding a Get Record Element to Find the Out of Office Messages 

The Get Records element will be used to find the out of office messages from the user records. 

  1. Under Toolbox, select Element
  2. Drag-and-drop Get Records element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Select the User object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: User | Out_of_office_Start_Date__c
      2. Operator: Less Than or Equal
      3. Value: {!$Flow.CurrentDate}
    2. Click Add Condition
    3. Row 1:
      1. Field: User | Out_of_office_End_Date__c
      2. Operator: Greater Than or Equal
      3. Value: {!$Flow.CurrentDate}
  7. How Many Records to Store:
    1. select All record
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

               

Step 2.3: Salesforce Flow – Using Decision Element – Does Out of Office Messages Found?

Now add the Decision element to decide whether or not we found the out of office messages. If the Resource (record collection variable) is null, then it means there are no out of office messages was found. You can take help from the screenshot below:

  1. Under Toolbox, select Element
  2. Drag-and-drop Decision element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Out_of_Office_Messages}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done.

Step 2.4: Salesforce Flow – Loop to Retrieve Records from Collection Variable 

  1. Drag-and-drop the Loop element onto the Flow designer. 
  2. Enter a name in the Label (Extract Record) field – the API Name will auto-populate.
  3. For Collection Variable select {!Out_of_Office_Messages}.
  4. For Specify Direction for Iterating Over Collection select the option First item to last item.
  5. Click Done

Step 2.5: Salesforce Flow – Using Decision Element – Check if the Loop Variable Contains Names Mentioned in the Chatter Post

Now add the Decision element to decide whether or not the loop variable contains names mentioned in the chatter post. You can take help from the screenshot below:

  1. Under Toolbox, select Element
  2. Drag-and-drop Decision element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.Body}
      2. Operator: Contains
      3. Value: {!Extract_Record.Name}
  6. Click Done.

Step 2.6: Salesforce Flow – Adding Values to a Record Variable

  1. Create a Record Variable varRFeedComment of type Feed Comment to create an out of post comment.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label (Construct OOO Comment) field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRFeedComment.CommentBody}
      2. Operator: Equals
      3. Value: {!Extract_Record.Out_of_office_Message__c}
    2. Click Add Assignment 
    3. Row 2:
      1. Field: {!varRFeedComment.CommentType}
      2. Operator: Equals
      3. Value: TextComment
    4. Click Add Assignment 
    5. Row 3:
      1. Field: {!varRFeedComment.FeedItemId}
      2. Operator: Equals
      3. Value: {!$Record.Id}
    6. Click Add Assignment 
    7. Row 4:
      1. Field: {!varRFeedComment.CreatedById}
      2. Operator: Equals
      3. Value: {!Extract_Record.Id}
  5. Click Done.

Step 2.7: Salesforce Flow – Adding Values to a Record Collection Variable

  1. Create a Record Collection Variable varRFeedComments of type Feed Comment to store record variable (created in step 2.6) for the bulk process.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label (Add Records into a Collection) field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRFeedComments}
      2. Operator: Add
      3. Value: {!varRFeedComment}
  5. Click Done.

Step 2.8: Salesforce Flow – Create Records to Associate Files and Lead Record 

  1. Drag-and-drop the Create Records element onto the Flow designer. 
  2. Enter a name in the Label (Create Records from Collection) field- the API Name will auto-populate.
  3. For How Many Records to Create select Multiple.
  4. Map Record Collection: {!varRFeedComments}
  5. Click Done.

In the end, Corey’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: 51
  5. Interview Label: Out of Office Automation {!$Flow.CurrentDateTime}
  6. Click Save

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

Proof of Concept

From now onwards, if a user posts a message to Chatter and tagged users who have out of office message setup, then Salesforce Flow will automatically add an out of office comment to it. 

  1. To test this functionality, create Out of Office messages for Few Users.
  2. Create a TextPost or LinkPost and mention the few users for whom you have created Out of Office messages.

Formative Assessment:

I want to hear from you!  

What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes? 

Make a post and tag me on Twitter @automationchampusing #AutomationChampion. 

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)

19 thoughts on “Out of Office Notification For Chatter Post

  1. @Rakesh Can you tell me how one can have the functionality working if someone @mention a user to an existing chatter post? I have this working for a chatter post but if someone comments on the chatter post it doesn’t seem to be posting OOF response in that case.

  2. This is really fantastic. I was working on doing this exact thing, but my method was WAY more complicated and I couldn’t get it to work. If I had gotten it working I was going to post it to the AppExchange… would you mind if I did that with this, fully crediting you for the solution? I think the community would appreciate it.

  3. Hello!

    Thanks for this post, this feature looks terrific. However, I can’t get to make it work…
    I followed all your steps but had a problem at step 10.
    For the left variables, I manage to get {!SingleUserDetails.Body} (instead of {!SingleUserDetails.CommentBody}), {!SingleUserDetails.Type} (instead of {!SingleUserDetails.CommentType}) and {!SingleUserDetails.CreatedById}. However, I do not have any variable called {!SingleUserDetails.FeedItemId}. The only variables I get that are Ids are : CreatedByID, ParentId and RelatedRecordId.

    Could you help me out?

    Thanks in advance!

    Regards,
    Emmanuelle

    1. Emmanuelle, I am having similar issues as well. Can you explain how did you get the SingleUserDetails.CommentBody to work. I am new Visual builder as well

      1. Thanks Rakesh, I got it to work :). I am having one final issue with the step 13 of connecting all the boxes. I couldn’t get the Option to say “Not mentioned”.

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