I'm trying to 'ORDER BY' a String field which contains numbers. It orders like this:

1 10 2 3 ...

I've tried whith LPAD, VALUE, *1, but nothing works.

THANKS all for ur help!

  • CAST doesnt work btw
    – Carloss
    Aug 25, 2015 at 8:01

1 Answer 1


Two possible options I can think of right now:


  • Populate a map based on your query results, use this field as Integer key (use Integer.valueOf)
  • Convert the keySet into a list and apply sort
  • Iterate the list and fetch the map for results in sequence


  • Add a formula field with return type as number and use it in ORDER BY clause.

Not the answer you're looking for? Browse other questions tagged .