You need to sign in to do that
Don't have an account?
read only Group using trigger
Hi,
how to create a read-only group + like + comment and not being able to post for members except admin and owner
* how to use triggers on the FeedItem in this group?.
trigger:_______________________________________
trigger GroupReadOnly on FeedItem (after insert) {
CollaborationGroup gp = [Select OwnerId, Id From CollaborationGroup Where Name = 'Group_ReadOnly'];
List<FeedItem> feedItems = new List<FeedItem>();
for(FeedItem item : trigger.new){
if(item.ParentId == gp.Id)
{
feedItems.add(item);
}
}
if(feedItems.size() >0) GroupReadOnlyClass.FilterFeedItems(feedItems);
}
class:_______________________________________
public class GroupReadOnlyClass{
public static void FilterFeedItems(List<FeedItem> feedItems){
Id[] listFeedItemToDelete = new Id[]{};
CollaborationGroup gp = [Select OwnerId, Id From CollaborationGroup Where Name = 'Group_ReadOnly'];
for(FeedItem item :feedItems){
if(item.ParentId == gp.Id)
{
if(item.InsertedById != gp.OwnerId){
listFeedItemToDelete.add(item.Id);
}
}
}
if (listFeedItemToDelete.size() > 0 )
{
DeleteFeedItems.DeleteFeedItems(listFeedItemToDelete);
}
}
}
class delete:________________________
public class DeleteFeedItems
{
@future
public static void DeleteFeedItems(Id[] listFeedItemToDelete)
{
if (listFeedItemToDelete.size() > 0 )
{
List<FeedItem > feedItems= [Select Id FROM FeedItem where Id=: listFeedItemToDelete];
if ( feedItems != null)
{
delete feedItems;
System.Debug(feedItems.size() + ' Feeds deleted !');
}
}
}
}
thx.
All Answers
solution:
Trigger: _______________________________________________
trigger GroupReadOnly on FeedItem (before insert) {
CollaborationGroup gp = [Select OwnerId, Id From CollaborationGroup Where Name = 'Group_ReadOnly'];
List<FeedItem> feedItems = new List<FeedItem>();
for(FeedItem item : trigger.new){
if(item.ParentId == gp.Id)
{
feedItems.add(item);
}
}
if(feedItems.size() >0) GroupReadOnlyClass.FilterFeedItems(feedItems);
}
Class:______________________________________________________________
public class GroupReadOnlyClass{
public static void FilterFeedItems(List<FeedItem> feedItems){
CollaborationGroup gp = [Select OwnerId, Id From CollaborationGroup Where Name = 'Group_ReadOnly'];
for(FeedItem item :feedItems){
if(item.ParentId == gp.Id)
{
if(UserInfo.getUserId()!= gp.OwnerId){
item.addError('You cannot post! Just Owner can post in this group');
}
}
}
}
}