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
Developer_shaanDeveloper_shaan 

Issue sorting with null values

Hello,

 

Using soql query i am able to sort the records. The records are being sorted based on a  field in  asc or descending order.

 

But i am not able to sort the null values.(I.e) when used ascending order the null values should be at the top and when teh order is desc the null values should come at last.

 

Please let me know if any one has soln for this.

 

Thanks

shaan

Ispita_NavatarIspita_Navatar

As a rule the null values will always come at the top whether you are sorting in ascending or decending order a way to solve this is to have a a dummy field corresponding to the field on which you are sorting say is a field-  Mailing Street is of type text. Then try using a dummy_Mailing _Street__c as a formula field which when the field is null assign it the smallest possible text value say 'a ' and then in your query sort on this dummy field.

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

Developer_shaanDeveloper_shaan

Thansk for the reply.

But here i need to sort based on particular fields .

I got a solution for this ..  the records are validated not to be null.

David81David81
RIyas BasheerRIyas Basheer
Hi

You can use SOQL like this.
SELECT Name
FROM Account
ORDER BY Name DESC NULLS LAST


Anitha Reddy AletiAnitha Reddy Aleti
Worked.Thanks