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
Manj_SFDCManj_SFDC 

sorting by multiple columns in apex

Hello guys,

I need to write a SOQL with sorting on 2 columns , start date and created date, can it possible to sort on multiple columns , or by default Apex considers only the first column used in sorting , please help
Thanks !
Best Answer chosen by Manj_SFDC
SandhyaSandhya (Salesforce Developers) 
Hi,

You can use sorting with 2 columns for example see below query
 
SELECT Name FROM Contact ORDER BY LastName DESC, FirstName DESC

Refer below link.

https://developer.secure.force.com/cookbook/recipe/sorting-query-results
 
Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
​Sandhya
 
 

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

You can use sorting with 2 columns for example see below query
 
SELECT Name FROM Contact ORDER BY LastName DESC, FirstName DESC

Refer below link.

https://developer.secure.force.com/cookbook/recipe/sorting-query-results
 
Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
​Sandhya
 
 
This was selected as the best answer
Saurabh Sood 12Saurabh Sood 12
Hi Manj,

SELECT Name FROM ObjectName ORDER BY CreatedDate ASC, start_date__c ASC
Let me know if u have any other concerns