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
PawelWozniakPawelWozniak 

SOQL ORDER BY and numbers ordering 16, 2, 8 instead of 2, 8, 16.

Is there a way to get from SOQL numbers ordered in natural order like 1, 5, 9, 10 not a 10, 1, 5, 9

 

I have query

SELECT Id, Name FROM  myObject__c ORDER BY Name ASC

 

results are passed to Visualforce apex:pageBlockTable where are displayed as:

 

Device 16
Device 2
Device 8

 

Users want to see them as 2,8,16.

Ankit AroraAnkit Arora

As I can understand it, you are using ASC and DESC on string and not on number. So string are are sorted in correct order "Device 16" is coming first as Device is conman and then 1 (of 16) should be at first place then 2 and so on. If you order by on number field for eg "2,16,8" then it will give you result as "2,8,16".

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page