ModerationRule
- Your org can have up to 30 rules. This limit is per org, not per site. This limit includes both content rules and rate rules.
- Each rule can have up to three keyword criteria.
- Rules that block content run first, followed by rules to review and approve content, then rules that replace content, and last by rules that flag content. If two or more rules perform the same action, the oldest rule runs first, based on the date the rule was created. Rules to replace content don’t run when the content also applies to a review rule—we want community managers to review the original content.
File Suffix and Directory Location
ModerationRule components have the suffix .rule and are stored in the moderation directory of the corresponding package directory. The file name format follows site_name.moderation_rule_developer_name.rule.
Version
ModerationRule components are available in API version 36.0 and later.
Special Access Rules
To view, create, edit, and delete moderation rules, you need the Manage Experiences or Create and Set Up Experiences permission. As of Spring ’20 and later, only users with permission to edit moderation rules can access this object.
Fields
ModeratedEntityField
The fields and entities you want to moderate.
Declarative Metadata Sample Definition
The following is an example of a ModerationRule component.
<?xml version="1.0" encoding="UTF-8"?>
<ModerationRule xmlns="http://soap.sforce.com/2006/04/metadata">
<description>Blocks Bad Word List in posts, comments, Link URLs, titles, and poll choices.</description>
<masterLabel>Blocking Rule</masterLabel>
<action>Block</action>
<active>true</active>
<userMessage>You can't use %BLOCKED_KEYWORD% or other inappropriate words in this site. Review your content and try again.</userMessage>
<!-- Applies the rule to FeedComment.RawCommentBody (an internal only field), if it contains words from the keyword list specified -->
<entitiesAndFields>
<entityName>FeedComment</entityName>
<fieldName>RawCommentBody</fieldName>
<keywordList>site1.badword_list</keywordList>
</entitiesAndFields>
<entitiesAndFields>
<entityName>FeedItem</entityName>
<fieldName>LinkUrl</fieldName>
<keywordList>site1.badword_list</keywordList>
</entitiesAndFields>
<!-- Applies the rule to FeedItem.RawBody (an internal only field), if it contains words from the keyword list specified -->
<entitiesAndFields>
<entityName>FeedItem</entityName>
<fieldName>RawBody</fieldName>
<keywordList>site1.badword_list</keywordList>
</entitiesAndFields>
<entitiesAndFields>
<entityName>FeedItem</entityName>
<fieldName>Title</fieldName>
<keywordList>site1.badword_list</keywordList>
</entitiesAndFields>
<entitiesAndFields>
<entityName>FeedPollChoice</entityName>
<fieldName>ChoiceBody</fieldName>
<keywordList>site1.badword_list</keywordList>
</entitiesAndFields>
</ModerationRule>
The following is an example package.xml that references the previous definition.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<name>ModerationRule</name>
<members>site1.blocking_rule</members>
</types>
<version>36.0</version>
</Package>
Wildcard Support in the Manifest File
This metadata type supports the wildcard character * (asterisk) in the package.xml manifest file. For information about using the manifest file, see Deploying and Retrieving Metadata with the Zip File.