0

我想知道如何创建一个只读组 + 喜欢 + 评论,并且无法为除管理员和所有者之外的成员发帖 * 如何在该组中的发帖上使用触发器?

我试过但它不起作用:

trigger N_GroupReadOnly on FeedItem (before insert) {

ID groupId = [Select Id from CollaborationGroup where Name = 'Group_ReadOnly'].Id;
CollaborationGroup ownerId = [Select OwnerId From CollaborationGroup Where Name = 'Group_ReadOnly'];
for(FeedItem item : trigger.new){
    if((item.ParentId == groupId) && (item.InsertedById != ownerId.OwnerId)){
        system.debug('you can not add post in this group');
        alert("you can not add post in this group");
        delete item ;
        return;
    }
    else{
        insert item;
    }
}

}

谢谢你。

4

1 回答 1

0

解决方案:

根据这个 developerforce.com 论坛条目:

扳机

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);

}

班级

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');                    
                }        
            }
        }

    }
}
于 2013-06-07T13:36:49.527 回答