Skip to main content
Hello, i am using transaction policy to prevent users from adding certain words on chatter post and comments by comparing with a list of words stored on object Banned Words:

Code:

global class TP02_BWChatterPostPolicyCondition implements TxnSecurity.PolicyCondition {

 //private string getQueryString() {

        //return 'SELECT Word__c FROM Banned_Word__c LIMIT 50000';

    //}

    

 public boolean evaluate(TxnSecurity.Event event) {

    String body = event.data.get('Body');

    Boolean o; 

    Boolean searchResults;

    Banned_Word__c[] banwrds = [SELECT Word__c FROM Banned_Word__c lIMIT 10000]);          // Each loop processes 200 items

        for(Integer i = 0; i<banwrds.size(); i++){

            Pattern pattern = Pattern.compile('.*\\b' + banwrds[i].Word__c + '\\b.*'); 

            Matcher m = pattern.matcher(body);

            if(m.find() > 0){

                searchResults = true; 

            }

            else{

                searchResults = false;

            } 

        }      

    return searchResults;

    }

}

 
1 answer
  1. Apr 23, 2019, 9:50 PM
    Can you elaborate as to what the issue is that you are facing? 
0/9000