Wednesday, June 25, 2014

How to have sorting in list for visualforce Salesforce

Many time when working with visualforce page to display list of records to the user the commonly asked feature is to have sorting. Sorting can be easy achieved by using standerd saleforce having the below structure :

[ORDER BY fieldExpression ASC | DESC ? NULLS FIRST | LAST ?]

or simply it can be written as :

SELECT Name FROM Account ORDER BY Name DESC NULLS LAST

But that is not the only way, we can do this by the below mentioned ways:
  • Sorting (Order By) in SOQL.
  • Using List methods to sort list.
  • Custom sorting.
Sorting (Order By) in SOQL.
Example : SELECT Name FROM Account ORDER BY Name DESC NULLS LAST

Using List methods to sort list.
Example : List.sort();

Using this method, you can sort primitive types and sObjects (standard objects, custom objects, and SelectOption). For more information on the sort order used for sObjects, see List Sorting. You can also sort your own custom types if they


Custom sorting.
Example : 

No comments:

Post a Comment