I have a Long Text Area(500) field Description__c on Account object. When i'm trying to search a keyword in this field value, it seems it's behaving as Case sensitive to find that keyword.

For e.g.

Description__c = 'Batch/lot number requested, not available at the time of call. Caller refused follow-up.'

String searchText = 'batch'
String searchtext1 = 'Batch'

When i'm trying to find searchText1 in Description__c, it's working fine. But when i'm trying to find searchText, it's returning false and not working.

I've already tried below ways to fix it.

1.  if(Account.Description__c.toLowerCase().contains(searchText.toLowerCase())){}
2.  if(Account.Description__c.toLowerCase().containsIgnoreCase(searchText.toLowerCase())){}
3.  if(Account.Description__c.containsIgnoreCase(searchText)){}

Please help me to fix this case sensitive behaviour of this long text area custom field.

1 Answer 1


I'm not sure why would you expect the results to work as case-insensitive. It's not something related to Long Text Area field. It's just because field returns a String & this is how apex treats Strings.

The string class already has methods to do both case-sensitive/insensitive checks.


Returns true if and only if the String that called the method contains the specified sequence of characters in substring.


Returns true if the current String contains the specified sequence of characters without regard to case; otherwise, returns false.

String description = 'Batch/lot number requested, not available at the time of call. Caller refused follow-up.',
    searchString = 'batch',
    searchString1 = 'Batch';

System.assert(description.contains(searchString1), 'Either the string was not part of actual string or the case didnt matched'); //passes
System.assert(description.containsIgnoreCase(searchString), 'The string was not part of actual string'); //passes

You just have to pick the correct one based on your requirement.

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.