You need to sign in to do that
Don't have an account?

Trigger on Chatter group to disable commenting from members based on profile ID
Hi there,
I am trying to disable the ability to comment in chatter groups based on profile ID. I have 3 groups: one public and two private. I want to disable all users with an "agent" profile from being able to comment in those specific groups. I am assuming this is a simple piece of code, but I am not able to create it on my own.
I have tried the following trigger, but it doesn't seem to be working. When i try to log in as an agent and do a post to a group the agent is a memeber of, it goes through. I also noticed this code does not include the name of the group that the user cannot post in. Anyone have any ideas? Thanks!
trigger ChatterCommentsDisabled on FeedComment (before insert) {
Id profileUser = UserInfo.getProfileId();
profile AnnuityProfile = [select id from profile where name ='D2D Agent User - Atlantic' or name ='D2D Agent User - Central'];
for(FeedComment fc : trigger.new)
if(fc.CommentType== 'ContentComment' && ProfileUser == AnnuityProfile.Id)
fc.addError('you dont have permissions to Comment');
}
I am trying to disable the ability to comment in chatter groups based on profile ID. I have 3 groups: one public and two private. I want to disable all users with an "agent" profile from being able to comment in those specific groups. I am assuming this is a simple piece of code, but I am not able to create it on my own.
I have tried the following trigger, but it doesn't seem to be working. When i try to log in as an agent and do a post to a group the agent is a memeber of, it goes through. I also noticed this code does not include the name of the group that the user cannot post in. Anyone have any ideas? Thanks!
trigger ChatterCommentsDisabled on FeedComment (before insert) {
Id profileUser = UserInfo.getProfileId();
profile AnnuityProfile = [select id from profile where name ='D2D Agent User - Atlantic' or name ='D2D Agent User - Central'];
for(FeedComment fc : trigger.new)
if(fc.CommentType== 'ContentComment' && ProfileUser == AnnuityProfile.Id)
fc.addError('you dont have permissions to Comment');
}
trigger ChatterCommentsDisabled on FeedComment (before insert) {
Id profileId=userinfo.getProfileId();
String annuityProfileName =[Select Id,Name from Profile where Id=:profileId].Name;
Boolean isRestrictedProfile = false;
if(String.isNotEmpty(annuityProfileName)){
if(annuityProfileName.equalsIgnoreCase('D2D Agent User - Atlantic')){
isRestrictedProfile = true;
}
if(annuityProfileName.equalsIgnoreCase('D2D Agent User - Central')){
isRestrictedProfile = true;
}
}
if(isRestrictedProfile){
for(FeedComment fc : trigger.new){
fc.addError('you dont have permissions to Comment');
}
}
}
Please mark it best if it helps you. Thanks.