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
JeeedeeeJeeedeee 

Find and text field with minus doen't find results

Hi,

I am trying find search results based on a custom text field on account, which contains the '-' minus character. The custom field is called Copy_Birthdate__pc and contains value "1982-01-19"

Since there is a minus, I have to escape it with a \ to use it in the Database.search, but I am not getting any values. Anybody has any idea why there are no results? In normal global search I can find the records

[code]
String safeSearchString = '1982\-01\-19';         
String searchQuery = 'FIND {' +safeSearchString +'} IN ALL FIELDS RETURNING Account(id, Name, Copy_BirthDate__pc  ) ,Contact(Id)';
System.debug('The value of searchQuery' +searchQuery);
List<List<SObject>> searchList = Search.query(searchQuery);
List<SObject> accounts =   searchList.get(0);
List<SObject> contacts =   searchList.get(1);
System.debug('Size of accounts: ' +accounts.size());
System.debug('Size of contacts: ' +contacts.size());
[/code]




JeeedeeeJeeedeee
First line is btw with double \\
String safeSearchString = '1982\\-01\\-19';