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
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%')
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.