function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MattMet86MattMet86 

Simple trigger for ChatterGroupMembership

Need some help creating a trigger that prevents users from leaving a company wide chatter group. Does anyone have some code they could share? 
alouie_sfdcalouie_sfdc
Here's a sample trigger that does what you're looking for:
trigger preventLeavingGroup on CollaborationGroupMember (before delete) {

    String groupId = '0F9D00000000n9R';

    for (CollaborationGroupMember member : trigger.old) {
        if (member.CollaborationGroupId.equals(groupId)) {
            System.assert(false, 'A trigger is preventing you from leaving this group.');
        }
    }

}