Get Comfortable Writing Chatter Policies with New Examples

We’ve added an example on how to write Chatter resource policies to the Apex Developer Guide.

You can scan or filter for specific words in posts. This example looks for a post containing the specific word “Salesforce” and blocks those posts. You can also write conditions that loop through a list of words or keep a running total of the occurrence of the words.

global class ChatterMessageWordFilterPolicyCondition implements TxnSecurity.PolicyCondition {
  public boolean evaluate(TxnSecurity.Event event) {
    String body = event.data.get('Body');

    if(body.containsIgnoreCase('Salesforce')) {
      return true;
    }
    return false;
  }
}