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
abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com 

Soql Order By no working correctly on datetime field

I have a inner soql query  in  which i am trying to get results order by a  date field mentioned below in code

Please help 

 Thanks in advance

map<id,contact> conmap=new map<id,contact>([SELECT Id, (SELECT Status,Subject,ActivityDate FROM Tasks ORDER by ActivityDate ) FROM Contact where id=:conid]);

 

Bhawani SharmaBhawani Sharma

Can you try after putting ASC or DESC keyword? Also share what results you are getting.

abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com

Asc and desc does makes changes but is not giving me the correct results .....developer console .... 

 

I have three dates (And as u can see below these are not sorted)

 

In  DESC  I get 

15:43:41:057 USER_DEBUG [18]|DEBUG|+++conmap++++2013-04-26 00:00:00

15:43:41:057 USER_DEBUG [18]|DEBUG|+++conmap++++2013-06-11 00:00:00

15:43:41:058 USER_DEBUG [18]|DEBUG|+++conmap++++2013-03-26 00:00:00

 

In Asc  I Get

 

15:45:28:042 USER_DEBUG [18]|DEBUG|+++conmap++++2013-04-26 00:00:00

15:45:28:043 USER_DEBUG [18]|DEBUG|+++conmap++++2013-03-26 00:00:00

15:45:28:043 USER_DEBUG [18]|DEBUG|+++conmap++++2013-06-11 00:00:00

 

 

THanks again

kiranmutturukiranmutturu
just to cross check try only soql
SELECT Status,Subject,ActivityDate FROM Tasks ORDER by ActivityDate ) and see the result...?
abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com
Problem SOrted
abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com

problem sorted

devKasparsdevKaspars

Just in case anyone else stumbles accross this - it appears that sorting in this instance failed because it was done in a map. If you do this for a list, it works just fine.