function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
thanushka_gunasekarathanushka_gunasekara 

Need help on SOQL Group By clause in APEX dev.

Following is an APEX class method I’ve written to return a list of results quarried by a SOQL statement.

 

public List<UserActivity_del__c> getCounts() {

        return [select Status__c,CPM_User__r.First_Name__c From UserActivity_del__c Group By Status__c,CPM_User__r.First_Name__c];

    }

 

But once I’ve put the group by statement it’ll give me an error saying “Error: cpmpage1con Compile Error: Return value must be of type: LIST<UserActivity_del__c> at line 11 column 9

 

My problem is did Group By clause changed the object type? Once I removed the group by clause then it works.

 

Thnaks.



Kevin SwiggumKevin Swiggum

Yes. Using the GROUP BY is going to change the return type to AggregateResult

 

Go here for more info

 

--Kevin