+ 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.