3

I'm doing this query:

 SELECT
      ID, Name, Email_Domain__c
    FROM
      Contact
        GROUP BY Email_Domain__c

And I'm getting this error

MALFORMED_QUERY: GROUP BY Email_Domain__c ^ ERROR at Row:5:Column:12 field 'Email_Domain__c' can not be grouped in a query call

Is there a way form to GROUP BY a custom field?

Pretty much what I want to do is in one call, get the domains for all the emails from the Contact object.

UPDATE

When I check this field in workbench, it has these 2 properties

calculatedFormula: RIGHT(Email,((LEN(Email)-(FIND("@",Email)))))

groupable: false
4
  • I think you answered your own question.
    – user6861
    Commented May 13, 2014 at 16:53
  • But, is there a way to make it groupable?
    – raygo
    Commented May 13, 2014 at 16:53
  • Pretty much what I want to do is in one call, get the domains for all the emails from the Contact object.
    – raygo
    Commented May 13, 2014 at 16:56
  • I see that formulas of types with "dense" set of expected values are groupable (like boolean or date) while "sparse" types are not groupable (e.g. string, dateTime, double)
    – hynekcer
    Commented Nov 5, 2014 at 14:41

2 Answers 2

11

Yes it's possible to group by custom fields in general, but not all field types are groupable.

The docs aren't particularly helpful from what I can see, and just tell you a field is groupable if it's describe field result has a groupable value of true.

IFIRC, you can group by pretty much anything, except DateTime, Long Text Areas, and Formulas, but unfortunately I can't seem to find any explicit documentation of this.

If you want to group by a formula field you can get by with by having creating a copy of the field and having workflow populate it, e.g. whenever your email domain field changes, do a field update that puts the value into the email domain (text) field. You can then use that to group.

0

Can you try this

SELECT Email_Domain__c
    FROM
      Contact
        GROUP BY Email_Domain__c

I agreed to Mr Ralph what is said .

You must log in to answer this question.

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