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.

  • When I executed the FIND {tim/&jacob} in Dev console I am getting the [{"message":"","errorCode":"MALFORMED_SEARCH"}] – Suresh May 13 '15 at 19:40
  • / isn't the escape character, \ is. – sfdcfox May 13 '15 at 21:17
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 + '\'';
| improve this answer | |
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 {\"}
| improve this answer | |
  • Using the proper escape character unfortunately doesn't work. – Jacob Raccuia May 14 '15 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 "\".

| improve this answer | |
  • I edited my question - after trying with "\\", I get a final result of {tim\&jacob} – Jacob Raccuia May 14 '15 at 13:07

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.