3

How do we write SOSL that searches lookup fields. Example My query looks this.

"FIND \'Mark\' in all fields returning Account(Id, Name, User.Name)"

Here it doesn't search User with keyword Mark.

Thanks

2

SOSL doesn't search "lookup" fields. For example:

FIND {Acme} IN ALL FIELDS RETURNING Contact(Id, FirstName, LastName, Account.Name)

Won't return contacts with the account called Acme; it will return any contacts that have any reference to Acme in the description field, name fields, etc.

Use a regular SOQL if you want to find accounts owned by a user:

SELECT Id, Name FROM Account WHERE Owner.Name LIKE 'Mark%'

Or, use SOSL with another term, and use an additional WHERE clause:

FIND {term} IN ALL FIELDS RETURNING Account(Id, Name, Owner.Name WHERE Owner.Name LIKE 'Mark%')
| improve this answer | |
  • I guess, SOSL for standard object relationship is working(however, on custom object it doesn't work despite of Lookup or MD relationship). Please confirm. Have tested standard object with following query(Burlington is account name): FIND {Burlington} IN ALL FIELDS RETURNING Contact – Ysr Shk Oct 16 '18 at 9:34
0

This may have something to do with the OWD on the User Object and your sharing settings on User in your Org (esp if it's set to private). As of SU15, sharing is respected in all classes for the User Object.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.