Disable Chatter Group joining Notification

Disable Chatter Group joining Notification

In Salesforce, when we add any User to a chatter group, an email notification is sent to the newly added user. It’s easy to disable this via UI but if you want to automatically add the newly created user into the chatter group, you don’t have a straight option. So in this article, I will show you how to disable chatter group joining notification.

First things first. We need to understand if there’s a setting in Salesforce that will allow us to disable chatter group joining notification email. Well, there it’s not specific to the joining email but the setting is to turn all chatter related email notifications off. Here’s an article by Salesforce you can follow to check this option. But what if the users are added to the chatter group via automation? In that case, you can’t use this option. Let me show you a use case and the solution.

Use Case

In Salesforce Experience Cloud Site, we are adding every new Community User to a Chatter Group automatically. But, we don’t want our customers to get the notification of being added into the group.

Solution Approach : Disable Chatter Group Joining Notification

So, to disable chatter group joining notification we need an automation that will disable the email notification before the User is added to the chatter group and enable it again once the user has joined. This way User will not get notification on joining and we re-enable the email notification setting for the user for future emails.

First things first, we need:

  1. Salesforce Object whose record is created once we add a User to a Chatter group. For that we have CollaborationGroupMember.
  2. We need the Object that stores Community User’s Details. For that, we have NetworkMember.
  3. Network ID of the Experience Cloud Site. To get the Network ID check the first point mentioned in this article.

Step 1: Get newly added Community User

Write an Apex Trigger in Before Context on CollaborationGroupMember Object. This will fetch the UserID of user who got added to the Chatter Group. Here’s the code snippet:

public static void beforeInsert(List<CollaborationGroupMember> newMemList) {
    Set<Id> userIds = new Set<Id>();
    for (CollaborationGroupMember mem : newMemList) {
        if(mem.MemberId != null){
            userIds.add(mem.MemberId);
        }
    }
    if(!userIds.isEmpty()){
        updateNetMem(userIds);
    }
}

Step 2: Disable Chatter Group Joining Notification

Use apex to fetch the NetworkMember record. A NetworkMember Represents a member of an Experience Cloud site and we need to update this records properties in order to disable the email setting.

public static void updateNetMem(Set<Id> userIds) {
	List<NetworkMember> netMemToUpdate = new  List<NetworkMember>();
	List<NetworkMember> netMembers = 
	[
		SELECT Id, MemberId, NetworkId,
		PreferencesDisableAllFeedsEmail 
		FROM NetworkMember
		WHERE MemberId IN : userIds
		AND NetworkId =: Label.CustomerPortalNetworkId
	];
	for(NetworkMember mem: netMembers){
		if(mem.PreferencesDisableAllFeedsEmail == False){
			mem.PreferencesDisableAllFeedsEmail = True;
			netMemToUpdate.add(mem);
		}
	}
	if(!netMemToUpdate.isEmpty()){
		update netMemToUpdate;
	}  
}

In the Above code, we are first fetching the NetworkMembers and then updating PreferencesDisableAllFeedsEmail field. This field when false, the member can automatically receive email for updates in the Experience Cloud site, based on the types of feed emails and digests the member has enabled. Also, we stored Network ID of the Experience Cloud Site in the custom label CustomerPortalNetworkId.

After this User will get added to the Chatter Group without receiving the Email Notification. Now, we need to re-enable the email notification so that this user gets all future emails.

Step 3: Re-enable Email Notifications

Create a Record Triggered Flow on CollaborationGroupMember and select ‘Action and Related Records’ so that our flow runs after the record is created. Check screenshot:

disable chatter group joining notification

Add a Scheduled Path and run an update operation after 2 min.

disable chatter group joining notification

Update the NetworkMember record again to enable the Email Notification Setting. Check below screenshot:

disable chatter group joining notification

In this way the Experience Cloud Site user will start receiving emails again. There could be other way to execute this order, maybe rather simpler. But with this post I just want to give you an idea to this solution. How you implement it is on you. I hope this helped.

In this way you can disable chatter group joining notification. In case you have any questions, hit me up on LinkedIn.

If you liked this post, do take a minute to read about Salesforce flow framework.

Share: