function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TilluTillu 

How to disable chatter posts for users ?

is it  possible to disable certain users from commenting to chatter posts. I have tried a trigger but how to include profile id  for this ?

I have tried but i don't think it gonna work..the user able to post on chatter..i want to restrict from profile.

trigger FeedCommentBefore on FeedComment(Before Insert) {
Id profileUser = UserInfo.getProfileId();

profile AnnuityProfile = [select id from profile where name = 'Annuity External Wholesaler'];
    for(FeedComment fc : trigger.new)
        if(fc.CommentType== 'ContentComment' && ProfileUser == AnnuityProfile.Id)
            fc.addError('you dont have permissions to Comment');
}
Best Answer chosen by Tillu
Vatsal KothariVatsal Kothari
Hi,

Your trigger is working perfect, have you tried comment with uploading attachment.
You are checking comment type with "ContentComment" so try to upload attachment it will restrict the user and if you want to restrict the user from commenting text also than try this:

if((fc.CommentType== 'ContentComment' ||  fc.CommentType== 'TextComment' ) && ProfileUser == AnnuityProfile.Id)
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal