1

I want to run a query that returns Cases ordered by status: "Escalated" first, "New" second, "Working" third, and "Closed" last. Can that be done without creating a formula field?

By the way my actual use-case involves a custom object.

2
  • Where's the query going to be used? i.e. Apex code?
    – Nick C
    Sep 21, 2017 at 0:19
  • @NickCook Yes in Apex.
    – Mossi
    Sep 21, 2017 at 0:19

1 Answer 1

2

Picklist values are ordered based on their order on the field setup page. So if you have, for example:

  • Escalated
  • Working
  • New
  • Closed

Then that will be the order, like if Escalated was 1, Working was 2... and so on.

The documentation states that:

The following limitations apply to data types when using ORDER BY:

...

picklist sorting is defined by the picklist sort determined during setup

...

So if you want a different order, you might just need to change the order of the values. If that is not an option, then you might need to use a formula, indeed.

1
  • Re-ordering the values is not an option unfortunately. I wanted to see if SOQL has a special way to order picklists -and it seems the answer is no. Thanks.
    – Mossi
    Sep 21, 2017 at 2:07

You must log in to answer this question.

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