+ Start a Discussion
Olivia DavisOlivia Davis 

SOQL Help - GROUP BY and MAX

Error: Field must be grouped or aggregated: et4ae5__Contact_ID__c. I need to return the Contact ID and the max DateOpened grouped by Contact. I don't think et4ae5__Contact_ID__c is a groupable field. This is in workbench SOQL query. Please help!

SELECT MAX(et4ae5__DateOpened__c),et4ae5__Contact_ID__c
FROM et4ae5__IndividualEmailResult__c
WHERE et4ae5__Opened__c=TRUE
GROUP BY et4ae5__Contact__c

This is the one I started with:

SELECT et4ae5__DateOpened__c,et4ae5__Contact_ID__c
FROM et4ae5__IndividualEmailResult__c
WHERE et4ae5__Opened__c=TRUE
ORDER BY et4ae5__DateOpened__c DESC
LIMIT 1
GROUP BY Contact_ID__c
Alain CabonAlain Cabon
Hi,

Your first request should be correct.

Is et4ae5__Contact_ID__c a formula field?

Checking for groupable:
 
https://workbench.developerforce.com/describe.php​

info > Standard & Custom Objects  : Fields > groupable

User-added image

Regards
Olivia DavisOlivia Davis
It is a formula field unfortunatley so, groupable: false. Not sure why they did it that way, could have been a lookup. et4ae5__Contact__c is groupable so I will keep trying with that.