SOQL ORDER BY - 2 Fields?

You need to separate fields with comma like this :

ORDER BY YOURFIELD1, YOURFIELD2

See the documentation : http://developer.force.com/cookbook/recipe/sorting-query-results


Since Priority is type text, you could not order in a way explained. It would order alphabetically.

e.g., High -> Low -> Urgent (Alphabetically)

So, you could create one more field that is numeric and can be sorted.

Priority: 1 (Urgent), 2 (High), 3 (Low)

Then you could write SOQL like:

SELECT Priority__c, Priority_Number__c, Age__c FROM Object__c ORDER BY Priority_Number__c ASC, Age__c ASC

Tags:

Sql

Soql