3

FIND {tim/?jacob} parses perfectly fine when running the query.

FIND {tim/&jacob} gives the following error:

line 1:10 mismatched character '&' expecting '}'`

what am I doing wrong?

According to Salesforce Developer Docs, the ampersand is possible to escape, as it is included in this list:

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

EDIT:

I used the wrong slash, which explains the above error.
When changing to FIND {tim\&jacob} as per the documentation, I get this parsing error.

Invalid string literal 'FIND {tim\&jacob} IN ALL FIELDS RETURNING '. Illegal character sequence '\&' in string literal.

When changing to FIND {tim\\&jacob}, I do not get an error, but the query is parsed as FIND {tim\&jacob} when I return it to me, and this returns 0 results.

2
  • When I executed the FIND {tim/&jacob} in Dev console I am getting the [{"message":"","errorCode":"MALFORMED_SEARCH"}]
    – Suresh
    Commented May 13, 2015 at 19:40
  • / isn't the escape character, \ is.
    – sfdcfox
    Commented May 13, 2015 at 21:17

3 Answers 3

2

I was able to figure this out by ignoring the documentation.

Find \' Tim&Jacob \' actually did the trick, with no escapes.

Since my string is actually held in a variable, here is my final code.

searchStr = 'Tim&Jacob';
String searchQuery = 'FIND \'' + searchStr + '\'';
1

That's some poorly written documentation.

Rewritten in an attempt to clarify:

Special characters that must be escaped using the escape character (\):

& | ! ( ) { } [ ] ^ " ~ * ? : \ '

Examples of escaping special characters:

  • Right Brace: Find {\}}
  • Asterisk: Find {\*}
  • Question Mark: Find {\?}
  • Single Quote: Find {\'}
  • Double Quote: Find {\"}
1
  • Using the proper escape character unfortunately doesn't work. Commented May 14, 2015 at 13:08
0

Try the backslash "\" to escape the special/reserved characters (you are using the slash "/" in your find sosl instead of "\"....). P.s. in some cases you may need to do a double escape "\".

1
  • I edited my question - after trying with "\\", I get a final result of {tim\&jacob} Commented May 14, 2015 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .