2

Question title covers most of it. Here's a sample query and the error I receive in response:

SELECT COUNT(Id) FROM MyCustom__mdt GROUP BY MyField__c

field Id does not support aggregate operator COUNT

Also experimented with other permutations:

SELECT COUNT(DeveloperName) FROM MyCustom__mdt GROUP BY MyField__c
SELECT COUNT(QualifiedApiName) FROM MyCustom__mdt GROUP BY MyField__c
SELECT COUNT(MasterLabel) FROM MyCustom__mdt GROUP BY MyField__c
SELECT COUNT(MyField__c) FROM MyCustom__mdt GROUP BY MyField__c

No luck.

Now this works, but it's not the same query and doesn't satisfy what I'm trying to do (the GROUP BY is important to me):

    SELECT COUNT() FROM MyCustom__mdt

1 Answer 1

3

GROUP BY does not seem to be supported for queries on custom metadata. If you refer to the Custom Metadata Type Limitations, the allowed SOQL syntax does not include GROUP BY.

SELECT fieldList [...]
FROM objectType
    [USING SCOPE filterScope]
[WHERE conditionExpression]
[ORDER BY field {ASC|DESC} [NULLS {FIRST|LAST}] ]
2
  • Ah, yep, looks like GROUP BY is not listed in the documentation. What's interesting then, is that COUNT() does work, despite being undocumented.
    – Grekker
    Aug 30, 2018 at 3:40
  • 1
    COUNT() is part of fieldList as documented in the SOQL Syntax documentation. So that’s the reason it works.
    – Jayant Das
    Aug 30, 2018 at 11:32

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.