2013-06-05 2 views
0

읽기 전용 그룹 + 주석을 만들고 admin과 소유자 이외의 회원을 게시 할 수없는 방법을 알고 싶습니다. 게시시 트리거를 사용하는 방법은 입니다. 이 그룹에?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');      
       }   
      } 
     } 

    } 
}