I am working on use case, where i need to search a keyword on a custom Object containing three Rich Text Fields. I am using the string method containsIgnoreCase(). But even if the field contains the keyword, i get false in return when i do ( Rich_Text__c.containsIgnoreCase(keyword) ). Am i doing something wrong here, or is there a better way to do this ?

Note :

  1. The Rich_Text__c records currently contain only texts with some HTML markups.
  2. I have done a SOQL Query to search on the Custom Object
  • 1
    I'm not able to replicate. If I query a record to variable obj with a rich text field Rich__c whose contents are <p><u>This is underlined.</u></p><p class="ql-indent-1">This is a keyword: <b>zebra</b>.</p> then obj.Rich__c.containsIgnoreCase('zebra') returns TRUE. Can you post come sample code to illustrate your exact problem? It's also not clear how SOSL fits into your scenario/problem. – Thomas Taylor May 17 '19 at 18:13
  • Sorry it was SOQL, updated my question to reflect it. – prabuddh kumar May 20 '19 at 10:03

Rich Text Fields are a tough nut to crack because of the different types of text/data that they can contain.

My suggestion is first convert this to a text field & use the string methods whatever you need

String Inputfield = yourObject.rich_text_field__c;

Inputfield = Inputfield.replaceAll('<[/a-zAZ0-9]*>','');
| improve this answer | |
  • 3
    stripHtmlTags would be more effective, actually. – sfdcfox May 17 '19 at 14:58
  • yay that's a good idea I think so – Pavan tej May 17 '19 at 15:23
  • Yes, stripping the HTML , worked for me . Thanks !! – prabuddh kumar May 20 '19 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.