ModerationRule defines how an Experience Cloud site moderates member-generated content. It combines content targets, keyword or member criteria, and a moderation action to protect the site from spam, bots, and inappropriate content. The active setting determines whether the rule runs.
A rule is separate from the keyword lists and member criteria it references. Metadata API rules can also target content more precisely than rules authored in Experience Management, including an individual field of a particular feed type.
Key Elements
| Element | What the Element Controls |
|---|---|
action |
Required. The moderation action: Block, Review, Replace, or Flag. The exposed value FreezeAndNotify is reserved for future use and is not an available moderation action. |
active |
Required. Whether the rule is active: true or false. |
type |
Required. Distinguishes a Content rule from a Rate rule. |
entitiesAndFields |
The content targets to moderate. Within each entry, required entityName identifies the object and fieldName identifies its field. |
keywordList |
Within an entitiesAndFields entry, references the keyword list used to evaluate that content target. A documented example is site1.badword_list. |
userCriteria |
References the member criteria used by the rule. This is separate from the content targets and their keyword lists. |
timePeriod |
The time period applied to a rate limit. Allowed values are Short and Medium. |
actionLimit |
The moderation-action limit for the rule. |
notifyLimit |
The notification limit for the rule, separate from actionLimit. |
masterLabel |
Required. The rule's display label, not its metadata component name. |
userMessage |
The feedback shown when content is blocked. The variable %BLOCKED_KEYWORD% can display up to five blocked words. |
Behavior and Constraints
Execution order and overlapping rules
Rules run in action order: Block, then Review, then Replace, and finally Flag. When multiple rules perform the same action, the oldest rule runs first, based on its creation date.
A Replace rule does not run when the content also matches a Review rule. This preserves the original content for review and approval.
An org can have up to 30 moderation rules across all sites. This total includes both content rules and rate rules; it is not a separate allowance for each site. Each rule can have up to three keyword criteria.
Content targets
The entitiesAndFields entries determine which content the rule examines. Posts and comments apply only to content created in groups and user profiles. All feed types, including polls and links, are supported.
Use these moderation-specific field selections for post and comment bodies:
- Feed posts:
entityName=FeedItemandfieldName=RawBody. - Feed comments:
entityName=FeedCommentandfieldName=RawCommentBody.
RawBody and RawCommentBody are not available in other APIs. Their absence from another API's object description does not make them invalid moderation targets.
Other documented targets include FeedItem.LinkUrl, FeedItem.Title, and FeedPollChoice.ChoiceBody. Targeting a post body does not establish coverage of those separate fields.
Access and blocked-content feedback
Viewing, creating, editing, or deleting moderation rules requires either Manage Experiences or Create and Set Up Experiences. Access to moderation rules is restricted to users permitted to edit them.
If userMessage is omitted, Salesforce displays its standard inappropriate-words message asking the member to review the content and try again. A custom message can use %BLOCKED_KEYWORD% to show up to five blocked words.
Deployment and Retrieval
ModerationRule components use the .rule suffix and reside in the moderation directory of the corresponding package directory. The file-name format is site_name.moderation_rule_developer_name.rule, such as site1.blocking_rule.rule.
The metadata component name, represented by the inherited fullName field, is site_name.moderation_rule_developer_name. The site prefix and period separator are part of the identity. For example, a package.xml manifest uses ModerationRule as the type name and site1.blocking_rule as the member name, not the value of masterLabel.
The manifest supports the wildcard member * for this type when retrieving metadata.
Do not edit API-created moderation rules in the Experience Management UI. The UI can overwrite relevant Metadata API fields or cause those fields to be ignored. Maintain API-created rules through the Metadata API to preserve their more precise content targeting.
To retain a rule's configuration without having it run, set active to false.
Relationships
Content references identify what the rule examines, while criteria references identify the keyword list or members used to evaluate it. The site-qualified component name is a naming association, separate from these element references.
References
-
CustomObject:entityNamewithinentitiesAndFields. -
CustomField:fieldNamewithinentitiesAndFields. -
KeywordList:keywordListwithinentitiesAndFields. -
UserCriteria: rule-leveluserCriteria.
Reported Issues
-
Direct Apex queries were reported as unavailable. A 2021 community inventory listed
ModerationRuleamong the Tooling API objects that were unavailable in the ApexSchemanamespace and could not be queried from Apex. This report concerns Apex query access, not Metadata API deployment or retrieval. See the Apex query-availability discussion.
Common Questions
How do I name a ModerationRule in package.xml?
Use ModerationRule as the type and a site-qualified member name such as site1.blocking_rule. Do not use the display label. The corresponding file is moderation/site1.blocking_rule.rule, and wildcard retrieval is supported.
Why can't I find RawBody or RawCommentBody in another API?
These fields are specific to moderation and are not available in other APIs. Use FeedItem.RawBody for post bodies and FeedComment.RawCommentBody for comment bodies in the rule's content targets.
Why does my Replace moderation rule not run?
A Replace rule does not run when the same content also matches a Review rule. Salesforce preserves the original content for review and approval. The overall action order is Block, Review, Replace, then Flag.
Can I edit an API-created moderation rule in Experience Management?
Do not edit it there. The UI can overwrite relevant API fields or cause them to be ignored, which can affect the rule's precise content targeting.
Is the 30-rule moderation limit per site?
No. The limit is 30 rules per org across all sites, counting both content rules and rate rules. Each rule can have up to three keyword criteria.