Getting Started with Salesforce Flow – Part 45 (Click and Join a Chatter Group)

Getting Started with Salesforce Flow – Part 45 (Click and Join a Chatter Group)

Big Idea or Enduring Question:

How do you create an automation that sends an email to users with a link to join Chatter Group? 

Chatter is a powerful Collaboration tool for your organization, for both internal users and partners. In the past, I have written a few articles which show how you can add a user to the Chatter group(s). There are a few situations when you want to send an email that contains a link, as soon ad user clicks on the link they will auto-join Chatter Group. This is the key technique one can use to promote collaboration in the organization. 

In this article, I will discuss how you can provide a link to join Chatter Group in an email to your users, so they can join Chatter Group as per their interest.

Objectives:

After reading this blog post, the reader will be able to:

  • Use a Screen a flow to add users to a chatter group 
  • Understand how to embed a flow into Visualforce Page 
  • Create an email template and add a quick link to join a Chatter group 
  • Use Schedule-Triggered Flow to automatically send email users to join Chatter Group

Business Use Case

Brenda David is working as a System administrator at Universal Containers (UC)She has received a requirement from the management to send one time email on 22nd December 2020 at 09:00 PM to their users with a link to join the newly created chatter group UC Internal Announcements, so they will auto-join the group as soon as they click on the link provided in the email.

Automation Champion Approach (I-do):

While this can be solved using various automation tools like Apex or Flow, we will use Screen Flow and Schedule-Triggered Flow
 
Before proceeding, ahead, understanding CollaborationGroupMember objects in Salesforce. It represents a member of a Chatter group.
 
Field Name Details
CollaborationGroupId Represent Id of the Chatter Group
MemberId Represent Id of the User (Group member)

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 8 steps to solve Brenda’s business requirement using Salesforce Flow. We must:

  1. Create a chatter group
  2. Find the chatter group Id
  3. Creating a custom label to store chatter group Id
  4. Salesforce Flow Steps: (Screen Flow)
    1. Add a get record element to find collaboration group record Id for the current user 
    2. Add a decision element to check the collaboration group id from the record variable (from step 4.1)
    3. Add a create records element to add a user to the chatter group 
  5. Create a visualforce page and embed flow into it
  6. Create an email template and add visualforce page as URL
  7. Create an email alert
  8. Salesforce Flow Steps:
    1. Define flow properties for schedule-triggered flow
    2. Use action to send out email alerts to users

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: Find the Chatter Group Id for UC Internal Announcements 

The next step is to find out the Id of the chatter group UC Internal Announcements. One possible workaround is to use the Developer Console. 

  1. Click Setup | Developer Console 
  2. In the Query Editor, run the following SOQL query 
    1. Select id, name from collaborationgroup where (name=’UC Internal Announcements’)
  3. Make sure to copy the Id. 

Step 3: Creating a Custom Label to Store Chatter Group Id

  1. Click Setup.
  2. In the User Interface, type Custom Labels.
  3. Click on the New Custom Label button.
  4. Enter Short Description the Name will auto-populate. 
  5. Now enter the UC Internal Announcement chatter group id in the Value.
  6. Click Save.

Step 4.1: Salesforce Flow – Adding a Get Record Element to Find Collaboration Group Member Id For the Current User

The Screen flow which we are creating will be used in the Visualforce page and later in the email template as in the URL. The next step is to find the Collaboration Group Member Id For the current user, to make sure that – the logged-In user is not already added to the group. To do that follow the below instructions:

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Screen Flow option and click on Create.
  5. Clicks on the Toolbox, select Element
  6. Drag-and-drop Get Records element onto the Flow designer. 
  7. Enter a name in the Label field; the API Name will auto-populate.
  8. Select the Record CollaborationGroupMember object from the dropdown list.
  9. Select All Conditions Are Met (AND).
  10. Set Filter Conditions
    1. Row 1:
      1. Field: CollaborationGroupId
      2. Operator: Equals
      3. Value: {!$Label.UC_Internal_Chatter_Group_ID}
    2. Click Add Condition
    3. Row 2:
      1. Field: Member
      2. Operator: Equals
      3. Value: {!$User.Id}
  11. How Many Records to Store:
    1. select Only the first record
  12. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  13. Click Done.

Step 4.2: Salesforce Flow – Using Decision Element to Check the Record Id from the Record Variable (from step 4.1)

Now we will use the Decision element to check the Record Variable from step 4.1 to find if it returns the record id or not. 

  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: {!Find_Member.Id}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.True}
  6. Click Done.

Step 4.3: Salesforce Flow – Create Records – Add Logged-In User to Chatter Group

The next step is to add a logged-In user to the chatter group. We will use the Create Records element. 

  1. Under Toolbox, select Elements. Drag and drop Create Records onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
    2. How Many Records to Create: One
    3. How to Set the Record Fields: Use separate resources, and literal values
    4. Object: CollaborationGroupMember
    5. Set Field Values for the Group Member
    6. Row 1:
      1. Row 1:
        1. Field: CollaborationGroupId
        2. Value: {!$Label.UC_Internal_Chatter_Group_ID}
      2. Click Add Field
      3. Row 2
        1. Field: RecordId
        2. Value: {!$User.Id}
  3. Click Done.

In the end, Brenda’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. Type: Screen Flow
  5. API Version for Running the Flow: 51
  6. Interview Label: Click and Join a Chatter Group {!$Flow.CurrentDateTime}
  7. Click Save

 

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

Now navigate to the flow details page and copy the flow Flow API Name.

Step 5: Create a Visualforce Page and Embed Your Flow Into It 

Now we will create a Visualforce force page and embed our flow into it. 

  1. Click Setup.
  2. In the Quick Find box, type Visualforce Pages.
  3. Clicks on the New button.
  4. Copy code from GitHub and paste it into your visualforce page
  5. Click Save.

Make sure to grant visualforce page access to all users. 

Step 6: Create an Email Template 

  1. Click Setup.
  2. In the Quick Find box, type Classic Email Templates.
  3. Clicks on the New button. 
  4. Name the HTML Email Template and make sure to select the Available For Use checkbox.
  5. Click Next and create a template like the following screenshot: 
    1. For button URL  https://yourdomain.lightning.force.com/apex/JoinCGroup

 

Step 7: Create an Email Alert 

  1. Click Setup.
  2. In the Quick Find box, type Email Alerts.
  3. Select Email Alerts, clicks on the New Email Alert button. 
  4. Name the Email Alert and click the Tab button. The Unique Name will populate. 
  5. For Object select User.
  6. For the Email Template chooses Invite to Chatter group
  7. For Recipient Type select Email Field: Email.
  8. Click Save.

Step 8.1: Salesforce Flow – 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 Schedule-Triggered Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
    2. Set Schedule
      1. Start Date: Dec 22, 2020
      2. Start Time: 9:00 PM
      3. Frequency: Once
      4. Click Done.
    3. Select Object: User
  5. Select All Conditions Are Met (AND)
  6. Set Condition
    1. Row 1
      1. Field: User | IsActive
      2. Operator: Equals 
      3. Value: True
  7. Click Done.

Step 8.2: Salesforce Flow – Call an Acton – Email Alert to Send Out reminder to Users

The next step is to call the Invite USer to Join CGroup email alert from flow so that when flow fires it triggers the email notification. 

  1. Under Toolbox, select Element
  2. Drag-and-drop Action element onto the Flow designer. 
  3. In the Action box, type Invite USer to Join CGroup.
  4. Clicks on the Invite USer to Join CGroup email alert. 
  5. Click Done.

In the end, Brenda’s Flow will look like the following screenshot:

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. Type: Schedule-Triggered Flow
  5. API Version for Running the Flow: 51
  6. Interview Label: Chatter Invitation {!$Flow.CurrentDateTime}
  7. Click Save

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

Proof of Concept

  1. As of now UC Internal Announcements – Chatter Group only has two members.
  2. On 22nd December at 09:00 PM scheduled job will run and start sending the invitations to users to join UC Internal Announcements – Chatter group.
  3. Once the users click on the link, they are automatically added to the chatter group UC Internal Announcements, as shown in the following screenshot:

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? 

Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

2 thoughts on “Getting Started with Salesforce Flow – Part 45 (Click and Join a Chatter Group)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.