3

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.

1 Answer 1

3

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 ...
4
  • it worked, thanks a lot! Commented Apr 13, 2019 at 17:40
  • so if i had multiple string vars, would I write it as 'phoneVal or emailVal' or would i need to keep it as ':phoneVal or :emailVal'? Commented Nov 20, 2023 at 20:28
  • 1
    @TristanBerger Not sure that syntax works. I'd just make it a normal string (e.g. searchTerm), and then merge that instead.
    – sfdcfox
    Commented Nov 20, 2023 at 22:29
  • thanks that worked, had to concat a few things but it worked! Commented Nov 21, 2023 at 21:15

You must log in to answer this question.

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