The above query results in an error
SELECT MAX(CreatedDate),OldValue,NewValue FROM LeadHistory GROUP BY OldValue,NewValue
The error :
ERROR at Row:1:Column:69 field 'OldValue' can not be grouped in a query call
Can someone explain this error ?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
If you execute this code in "Developer Console"/"Debug"/"Open Execute Anonymous Window":
System.debug('>>> isGroupable=' + LeadHistory.OldValue.getDescribe().isGroupable());
you will see that
false is returned and the documentation says:
isGroupable() Returns true if the field can be included in the GROUP BY clause of a SOQL query, false otherwise
So this is a limitation of the platform, and you will have to query the values ungrouped and use Apex code to achieve your desired logic instead.