【问题标题】:How to Create a read-only group in SalesForce如何在 SalesForce 中创建只读组
【发布时间】:2013-06-05 14:20:57
【问题描述】:

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

我试过了,还是不行:

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

}

谢谢。

【问题讨论】:

    标签: salesforce apex-code salesforce-chatter


    【解决方案1】:

    解决方案:

    as per this developerforce.com forum entry:

    触发器

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-18
      • 2010-10-20
      • 2021-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多