1

I was trying built aggregate query on number field, Found an strange behaviour.

Object Considered: Campaign

I have used Visual Code for execute SOQL for my analysis.

Use Case 1:

NumberOfContacts -> Standard Salsforce Number Field : Number(9, 0)

sfdx force:data:soql:query --query SELECT NumberOfContacts, COUNT(Id) FROM Campaign GROUP BY NumberOfContacts

Querying Data... done NUMBEROFCONTACTS COUNT(ID) ──────────────── ───────── 0 1 Total number of records retrieved: 1.

Use Case 2:

NumberSent -> Standard Salsforce Number Field : Number(18, 0)

sfdx force:data:soql:query --query SELECT NumberSent, COUNT(Id) FROM Campaign GROUP BY NumberSent

Querying Data... done ERROR running force:data:soql:query:
COUNT(Id) FROM Campaign GROUP BY NumberSent ^ ERROR at Row:1:Column:54 field 'NumberSent' can not be grouped in a query call

Use Case 3:

TestNumberField__c -> Custom Number Field : Number(9, 0)

sfdx force:data:soql:query --query SELECT TestNumberField__c, COUNT(Id) FROM Campaign GROUP BY TestNumberField__c

Querying Data... done ERROR running force:data:soql:query:
COUNT(Id) FROM Campaign GROUP BY TestNumberField__c ^ ERROR at Row:1:Column:69 field 'TestNumberField__c' can not be grouped in a query call

Question is why i am able run aggregate query on number standard number field which has length of 9, and unable to do on custom number field and standard number field which has length 18.

Is this a limitation of Salesforce ?

1 Answer 1

2

Certain fields are not groupable. For number fields, they are groupable if they are standard and are integer deep at the API level. For all other numbers they are decimals and are not groupable.

Can see more in this other question's chosen answer: What types of fields are groupable in a SOQL `GROUP BY` clause?

You must log in to answer this question.

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