---
schema_version: "1"
id: 7c9f104e3169e4dd52756a7a663d58a566931480cefd6da55e33dc3196939358
title: Moderate Feed Items with Triggers
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_feedItem_triggers.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_feedItem_triggers.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8ee18e4986ac8aa84b42a24bd755a2bd9374ef7759f116c849b3ce702445c6fb
description: Write a trigger for FeedItem to automate the moderation of posts in an org or Experience Cloud site. Use triggers to ensure that posts conform to your company’s communication policies and don’t contain unwanted words or phrases.
---
# Moderate Feed Items with Triggers

Write a trigger for FeedItem to automate the moderation of posts in an org or Experience Cloud site. Use triggers to ensure that posts conform to your company’s communication policies and don’t contain unwanted words or phrases.

<table class="editionTable" border="0" summary="Salesforce editions needed for the documented functionality" width="100%"><tbody class="tbody"><tr><td class="subHead">Available in: <strong class="ph b">Enterprise</strong>, <strong class="ph b">Performance</strong>, <strong class="ph b">Unlimited</strong>, and <strong class="ph b">Developer</strong> Editions</td></tr></tbody></table>

  

<table class="permTable sort_table" border="0" summary="Permissions needed for the documented functionality" width="100%"><tbody class="tbody"><tr><td class="permRowLeft">User permissions needed to save Apex triggers for FeedItem:</td><td class="permRowRight">Author Apex</td></tr></tbody></table>

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 **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.

trigger ReviewFeedItem on FeedItem (before insert) {
    for (Integer i = 0; i<trigger.new.size(); i++) {

        // We don't want to leak "test phrase" information.

        if (trigger.new\[i\].body.containsIgnoreCase('test phrase')) {
            trigger.new\[i\].status = 'PendingReview'; 
            System.debug('caught one for pendingReview');
        }
    }
}