[SalesForce] SOSL Multiple Search Words

Trying to search multiple terms in SOSL in APEX. I tried this singular, of course works:

[FIND 'searchOne' IN ALL FIELDS RETURNING ACCOUNT]

But these don't work:

  • [FIND 'searchOne' OR 'searchTwo' ....
  • [FIND {'searchOne','searchTwo'} ....
  • [FIND (searchOne', 'searchTwo') ....

Error is:

'(' not expected (or something..etc)

My goal is bulkification and searching a value in an Encrypted Field. I want to be able to get all matching records based on a set of terms.

Best Answer

In Apex, it's just a normal string:

[FIND 'searchOne or searchTwo' in all fields ...

This syntax is slightly different than the API, which is probably where the confusion is coming from. You can also use quotation marks (") to group terms, etc, just like you can in normal SOSL.

[FIND '"searchOne" or "searchTwo"' in all fields ...
Related Topic