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
Raja HejamadiRaja Hejamadi 

Apex/SOQL: Sorting results by a text field containing name of the month

I have a custom object with a text field having values that represent fiscal period ids -- in the form YY-MMM. For example: 14-Jan, 14-Feb, etc.
When I query this object and order by this period id, since the field is text, it orders chronologically -- i.e., in the order 14-Apr, 14-Aug, 14-Dec, 14-Feb, etc., -- which is useless.

What would be the easiest way to achieve a sort order assuming this field represents calendar periods?

I've thought of adding another custom table to map these to month number, but couldn't figure out how to do this without a lookup relationship.

Thanks.
 
Best Answer chosen by Raja Hejamadi
Mudasir WaniMudasir Wani
Create a formulae field and take the value of the month on that and sort by that field only.

Hope this helps !!!!!!

All Answers

Mudasir WaniMudasir Wani
Create a formulae field and take the value of the month on that and sort by that field only.

Hope this helps !!!!!!
This was selected as the best answer
Mudasir WaniMudasir Wani
Yes there is a function Month(date)
It will give you the integer as output 
Raja HejamadiRaja Hejamadi
Thanks.