ORDER BY clause

You can use one or more ORDER BY clauses in a SOSL statement.

Syntax

ORDER BY fieldname [ASC | DESC] [NULLS [first | last]]

Syntax Description
ASC or DESC Ascending (ASC) or descending (DESC) order of the results. Default order is ascending.
NULLS Order null records at the beginning (first) or end (last) of the results. By default, NULL values are sorted last in ascending order and first in descending order.

Examples

The following example shows a single ORDER BY clause:
FIND {MyName} RETURNING Account(Name, Id ORDER BY Id)
The following example shows multiple ORDER BY clauses:
FIND {MyContactName} RETURNING Contact(Name, Id ORDER BY Name), Account(Description, Id ORDER BY Description)

The following search returns a result with account records in alphabetical order by name, sorted in descending order, with accounts that have null names appearing last:

FIND {MyAccountName} IN NAME FIELDS RETURNING Account(Name, Id ORDER BY Name DESC NULLS last)
© Copyright 2000–2012 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.