Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, 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.
Moderate Feed Items with Triggers
| Available in: Enterprise, Performance, Unlimited, and Developer Editions |
| User permissions needed to save Apex triggers for FeedItem: | Author Apex |
Write an Apex before insert trigger to review the feed item body and change the status of the feed item if it contains a blocklisted 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 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}