7

We want to avoid, that a user is able to upload files to chatter comments. We realized this by creating triggers on FeedComment and ContentVersion. This prevents to save the comment successfully.

If a user selects a local file to upload, the file exists in the chatter files tab as content document record. The file exists, although our trigger works, which prevents saving file comments.

The same behaviour occurs, if a user click cancel after uploading the file while creating a comment.

A trigger on content document won't be called on upload. How can I prevent uploading chatter files?

5

You can write a BeforeInsert trigger on FeedItem / Comment as the case may be, I've just tried it, and not only does it block the comment, it also prevents upload of the file to Chatter Files.

Feed Item :

trigger FeedItemBefore on FeedItem (Before Insert) {
    for(FeedItem fi : trigger.new)
        if(fi.type == 'ContentPost')
            fi.addError('Cannot Upload Files');
}

Feed Comment :

trigger FeedCommentBefore on FeedComment(Before Insert) {
    for(FeedComment fc : trigger.new)
        if(fc.CommentType== 'ContentComment')
            fc.addError('Cannot Upload Files');
}
  • We use this triggers. No content feeds and content comments can be created. This works perfectly. But by doing the following steps, the file is listed in the chatter files tab: Click comment on a post, upload a file from the local computer, click comment. Now the error message from the trigger will be shown, as expected. But uploading the file won't be prevented. – user1902191 Oct 18 '13 at 7:25
  • @user1902191 I am experiencing the same issue you are. The trigger prevents the comment, but not the file attached to the comment. Even if the comment isn't posted due to the trigger error, the attached file is still uploaded. Did you ever find a solution? – smohyee Nov 9 '15 at 5:20
0

Works for the post chatter only where attachments are added Does not work for 'POST FILE'. Need a different trigger.

trigger FeedComment on FeedComment (before insert) {
//This loop blocks new posts with attachments
    for (FeedComment item : Trigger.new) {
        if(item.RelatedRecordID!=null){
            item.addError('Uploading of attachments are currently disabled until further notice. Please cancel your current Chatter post. - system admin');
        }
    }
}


trigger FeedTrigger on FeedItem (before insert){   
    //This loop blocks new posts with attachments
    for (FeedItem item : Trigger.new) {
        if(item.RelatedRecordID!=null){
            item.addError('Uploading of attachments are currently disabled until further notice. Please cancel your current Chatter post. - system admin');
        }
    }
  • From Review: To improve your answer please add more information on how this solves the problem. Just posting code isn't very helpful most of the times. – Markus Slabina Aug 24 '17 at 7:41
  • it solved the original problem. issue was code in trigger. and I posted my comments up top. – Jim Okere Aug 26 '17 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.