According to the documentation you need to escape the following special characters in SOSL search text.

Escaping special characters & | ! ( ) { } [ ] ^ “ ~ * ? : \ '

The - dash character is not in that list, yet when I attempt SOSL with the - dash character in the search text I get the following error:

line 1:14 mismatched character '-' expecting '}'

A sample SOSL that returns the error is:

FIND {some-email@gmail.com} IN EMAIL FIELDS RETURNING Lead, Contact

When I escape the - dash character the SOSL query works just fine.

FIND {some\-email@gmail.com} IN EMAIL FIELDS RETURNING Lead, Contact

Am I doing something wrong, is this a bug in Salesforce, or is the documentation incomplete?


Not sure why that part of the documentation is not mentioning - and + characters, but they are reserved according to this documentation:

Reserved Characters

The following characters are reserved: ? & | ! { } [ ] ( ) ^ ~ * : \ " ' + -

Reserved characters, if specified in a text search, must be escaped (preceded by the backslash \ character) in order to be properly interpreted. An error occurs if you do not precede reserved characters with a backslash. This is true even if the SearchQuery is enclosed in double quotes.

  • 3
    It appears your documentation is better than mine. – dBeltowski Sep 13 '16 at 19:18

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.