function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gnanendra Kumar GotappagariGnanendra Kumar Gotappagari 

find the particular words in sentence using soql

Hi All,

im trying to find the Offencive words in the sentence ,How can i write the Query for that.please helap me.


Thanks In Advance
G.kumar
Best Answer chosen by Gnanendra Kumar Gotappagari
Arunkumar RArunkumar R
You need to check contains in that specfic string.

Try the below code,
 
trigger ideaOffensive on IdeaComment (Before Insert,Before Update) {


    for(IdeaComment a:Trigger.new)
    {
      if (a.CommentBody != null && a.CommentBody.contains('idiot'))
      {
        a.CommentBody.addError('Senence having Offencive word'); // prevent update
        }
}
}

All Answers

Gnanendra Kumar GotappagariGnanendra Kumar Gotappagari
wrote this trigger , but it's not working in sentence

trigger ideaOffensive on IdeaComment (Before Insert,Before Update) {


    for(IdeaComment a:Trigger.new)
    {
      if (a.CommentBody=='idiot')
      {
        a.CommentBody.addError('Senence having Offencive word'); // prevent update
        }
}
}
 
Arunkumar RArunkumar R
You need to check contains in that specfic string.

Try the below code,
 
trigger ideaOffensive on IdeaComment (Before Insert,Before Update) {


    for(IdeaComment a:Trigger.new)
    {
      if (a.CommentBody != null && a.CommentBody.contains('idiot'))
      {
        a.CommentBody.addError('Senence having Offencive word'); // prevent update
        }
}
}
This was selected as the best answer
Arunkumar RArunkumar R
To ignore case sensitive,

Use  a.CommentBody.containsIgnoreCase('idiot') instead of a.CommentBody.contains('idiot') in line number 6.
Gnanendra Kumar GotappagariGnanendra Kumar Gotappagari
Thanks Arun It's Working....