-1

I have a trigger on FeedComment which is intended to prevent file upload in FeedComment, below is the code. It shows the popup error msg on the screen but in backend it inserts ContentVersion,ContentDocument and ContentDocumentLink. Can anyone please help me, as in how can we stop the dml on the above three objects.

trigger FeedCommentBefore on FeedComment(Before Insert) {
    for(FeedComment fc : trigger.new)
        if(fc.CommentType== 'ContentComment')
            fc.addError('Cannot Upload Files');
}
1

Files are uploaded before being attached to the Comment. You would have to prevent all file uploads. Otherwise a user could upload a file, then copy a link and insert it into the comment body.

Why do you want to prevent file uploads in comments?

2
  • And how we we prevent file upload from chatter? Client told that they dont' want anyone to upload files in chatter for security reasons.
    – Rijia
    Jun 2 '19 at 8:04
  • 1
    Documentation on disabling File Upload help.salesforce.com/…
    – Paul B.
    Jun 4 '19 at 18:47

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.