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
Ross Gilbert 18Ross Gilbert 18 

Code review on trigger that prevents record insertion

This trigger simply prevents a user from inserting a record on an object.  It's not bulkified since the whole point is to prevent any record from being inserted at all.   It works fine but I wanted to check with the community to see if anyone sees anything wrong with the code or if it might be improved:
 
trigger FeedItemTrigger on FeedItem(Before Insert){

    /*Ross Gilbert 6/9/2015: The following prevents a Salesforce user from inserting any new Feed Item object in Salesforce*/
 
    for(FeedItem fi: trigger.new){
        fi.addError('Chatter is not currently supported for Salesforce.  You are not allowed to create new chatter posts or comments at this time.');
    }
}
What do you think?
 
andy81andy81
Hi Ross,

everything looks to be fine with the code but what if a user wants to comment on a already existing feeditem. I guess to restrict people even from commenting use the same snippet of code for feedcomment also.
Ross Gilbert 18Ross Gilbert 18
Exactly.  I've got the same trigger on Feed Comment.  So even if you had my code above not in place, the trigger on Feed Comment would prevent commenting on any existing post.  Does that make sense?  Thanks a lot for taking a look.
andy81andy81
Perfect.