SOSL query searching in multiple fields

1.9K    Asked by AnkitChauhan in Salesforce , Asked on Jul 1, 2021

I want to search in multiple fields using SOSL. I know that it allows to search in all fields using below syntax-

FIND {"Smith"} IN ALL FIELDS RETURNING contact (name), lead (name)
And also works perfectly fine with single field if I supply any field's name instead of ALL like below-
FIND {"Smith"} IN Name FIELDS RETURNING contact (name), lead (name)

What I want to try is something like below-

FIND {"Smith"} IN (NAME, COMPANY) FIELDS RETURNING contact (name), lead (name)

I have tried various things here for IN (NAME, COMPANY) like below-

    • IN NAME, COMPANY
      IN {NAME, COMPANY}
      IN NAME; COMPANY

Can someone please suggest if there is a way of doing it in SOSL.

Answered by Bruce Benedict

Using query you can't specify individual fields this way. The only options for IN X FIELDS are:

  • ALL FIELDS
  • NAME FIELDS
  • EMAIL FIELDS
  • PHONE FIELDS
  • SIDEBAR FIELDS

If you'd like, you can provide filters on the individual objects, such as:

FIND :term IN ALL FIELDS RETURNING Lead(Name, Company WHERE Name LIKE :filter OR Company LIKE :filter)...



Your Answer

Answer (1)

Hello, since you can't combine the results in a single SOSL query, you would need to execute both queries separately in your code and then combine the results programmatically. Check out brawl stars online to know more information.

4 Weeks

Interviews

Parent Categories