Creating a group that allows read-only access

To make a group that allows read-only access will mean that only the owner of the group is allowed to post in the group—you need to write a trigger on FeedItem to achieve this. In an organization, an admin can use this type of group to post news, articles, and so on.

The sample code is given as follows:

CollaborationGroup groups = [Select OwnerId, Id From CollaborationGroup Where Name = 'Chatter App'];
List
<FeedItem>
  feedItems = new List
  <FeedItem>
    ();
    for(FeedItem items : trigger.new)
  {
  if(items.ParentId == groups.Id && UserInfo.getUserId()!= groups.OwnerId)
  {
  items.addError('Only Owner can post in this group'),
  } 
  }

Here, we are taking groups from the CollaborationGroup object. Select ownerId; that is the ID where the group name is Chatter App. Then we iterate on a list of FeedItem named feedItems, make a trigger if the user is not the group owner (here we check it using the if condition by checking IDs), and show the Only Owner can post in this group error.

Creating a group that allows read-only access

In the preceding example, the user is trying to post a message on the Chatter App read-only group, and he sees an error as he is not owner of this group.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.35.72