Newer Version Available

This content describes an older version of this product. View Latest

Moderate Feed Items with Triggers

Write a trigger for FeedItem to automate the moderation of posts in an organization or community. Use triggers to ensure that posts conform to your company’s communication policies and don’t contain unwanted words or phrases.
Available in: Enterprise, Performance, Unlimited, and Developer Editions

User Permissions Needed
To save Apex triggers for FeedItem: “Author Apex”

This release contains a beta version of the pre-moderation feature, which means it’s a high-quality feature with known limitations. This feature isn’t generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. We can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features. You can provide feedback and suggestions for this feature in the Community Implementation group in the Success Community.

Note

Write an Apex before insert trigger to review the feed item body and change the status of the feed item if it contains a blacklisted phrase. To create a trigger for feed items from Setup, enter FeedItem Triggers in the Quick Find box, then select FeedItem Triggers. Alternatively, you can create a trigger from the Developer Console by clicking File | New | Apex Trigger and selecting FeedItem from the sObject drop-down list.

This example shows a before insert trigger on FeedItem that is used to review each new post. If the post contains the unwanted phrase, the trigger also sets the status of the post to PendingReview.

1trigger ReviewFeedItem on FeedItem (before insert) {
2    for (Integer i = 0; i<trigger.new.size(); i++) {
3
4        // We don't want to leak "test phrase" information.
5
6        if (trigger.new[i].body.containsIgnoreCase('test phrase')) {
7            trigger.new[i].status = 'PendingReview'; 
8            System.debug('caught one for pendingReview');
9        }
10    }
11}