• William Yeh
  • NEWBIE
  • 0 Points
  • Member since 2014
  • ISV Technical Evangelist
  • Salesforce


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I've had some trouble with SOSL in escaping wildcard characters (* and ?).  From the SOSL documentation (http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_sosl_find.htm), it seems like * should be escaped with \* or possibly \\* or even \\\\*, but none of those seem to work.

These are the results I saw:
[FIND 'pre*post' IN ALL FIELDS RETURNING Lead(Id, Name)];  // works as a wildcard
[FIND 'pre\*post' IN ALL FIELDS RETURNING Lead(Id, Name)];  // error: Invalid string literal 'pre\*post'. Illegal character sequence '\*' in string literal.
[FIND 'pre\\*post' IN ALL FIELDS RETURNING Lead(Id, Name)];  // error: Invalid string literal 'pre\*post'. Illegal character sequence '\*' in string literal.
[FIND 'pre\\\\*post' IN ALL FIELDS RETURNING Lead(Id, Name)]; // seems to function as wildcard same as no backslash

Similar behavior is observed with ? instead of *.

Any help?  Thanks in advance!