2013-06-05 62 views
0

創建一個只讀組我想知道如何創建一個像+評論只讀組+,不能夠張貼除了管理員和所有者 成員*如何在發佈使用觸發器在這個組裏?如何在Salesforce的

我試過,但它不工作:

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

}

謝謝。

+0

無解!! :-( – Zero0o

回答

0

解決方案:

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

    } 
}