function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mark CrooksyMark Crooksy 

How can I order the results of a FIND query?

This query returns results in record id order:
FIND {word*} IN Name FIELDS RETURNING contact (contact.Id, contact.Salutation, contact.FirstName, contact.LastName, contact.Title, contact.Email);

What I would like to achieve is something like:
FIND {word*} IN Name FIELDS RETURNING contact (contact.Id, contact.Salutation, contact.FirstName, contact.LastName, contact.Title, contact.Email) ORDER BY LastName ASC

Would anyone know if this is possible?
Thanks,

Mark
Best Answer chosen by Mark Crooksy
SonamSonam (Salesforce Developers) 
Mark, I think you can use the ORDER BY like the following:
FIND {word*} IN Name FIELDS RETURNING contact (contact.Id, contact.Salutation, contact.FirstName, contact.LastName, contact.Title, contact.Email ORDER BY LastName ASC )

reference:
http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_sosl_select_order_by_with_limit.htm
 

All Answers

SonamSonam (Salesforce Developers) 
Mark, I think you can use the ORDER BY like the following:
FIND {word*} IN Name FIELDS RETURNING contact (contact.Id, contact.Salutation, contact.FirstName, contact.LastName, contact.Title, contact.Email ORDER BY LastName ASC )

reference:
http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_sosl_select_order_by_with_limit.htm
 
This was selected as the best answer
Mark CrooksyMark Crooksy
Perfect! Thanks for replying.