How to prevent Chatter Posts on Salesforce Case Comments?

How to prevent Chatter Posts on Salesforce Case Comments?

To prevent Chatter Posts on Salesforce Case Comments, we can develop a trigger on FeedComment object or entity.

addError() method on the apex trigger can be use to throw the relevant error messages.

Sample Trigger:

trigger FeedCommentTrigger on FeedComment ( 
    before insert 
) {
    
    for ( 
        FeedComment objFC : trigger.new
    ) {
        
        if (
            String.valueof(
                objFC.ParentId
            ).startsWith(
                '500'
            )
        ) {
            
            objFC.addError(
                'You cannot chatter on Case Comment'
            );
            
        }
        
    }

}

Output:

Leave a Reply