SOSL query searching in multiple fields

1.6K    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

Interviews

Parent Categories