Cannot sort on a soql-request in a custom meta data type. When i perform SELECT .. FROM x__mdt WHERE ... ORDER BY x. Then field x cannot be numeric to get a correct order. Change it to a string-field ordering works ok. Playing with ASC/DESC makes no difference!

  • 2
    Is there a question here?
    – Keith C
    Oct 27, 2016 at 12:30

2 Answers 2


You can only order by a field that's in the SELECT clause of the query for custom metadata types -- see p.3 of the Custom Metadata Types Implementation Guide for more information on query limitations.

  • Thanks I missed that one 'SELECT .. FROM x__mdt WHERE ... ORDER BY x'. must be 'SELECT x FROM x__mdt WHERE ... ORDER BY x'.
    – WvB
    Oct 28, 2016 at 7:32
  • The limitation of having to select a field to be able to order by it is now fixed. See the other answer for details.
    – Phil W
    Feb 3 at 9:04

Update The known issue has been resolved in Spring `21.

See the known issue Custom Metadata Type not being sorted as expected.

Sorting order not being used in SOQL with Custom Metadata Type when sort field is not in column queried. This result in the order not being returned properly with Flows, API, Apex, and any functionality which would use a SOQL query for Custom Metadata Type.


Workaround ==== You can only use ORDER BY when the ordered field is a selected field.

  • 2
    This is now fixed and rolled out.
    – Phil W
    Feb 3 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.