+ Start a Discussion

Aggregate Results

I'm trying to figure out how to use aggregate results and just can't seem to get it.  I've copied this exact statement from the Apex Code Developer's Guide into an otherwise valid class:


AggregateResult[] groupedResults = [SELECT CampaignId, AVG(Amount) test,  FROM Opportunity GROUP BY CampaignId];


I get the error "Invalid Type: AgregateResult".


Obviously, I'm missing the boat somewhere.  Can anyone enlighten me about what I'm doing wrong?



Best Answer chosen by Admin (Salesforce Developers) 
Is your class set for version 18 ?

All Answers

Is your class set for version 18 ?
This was selected as the best answer
Are you on a system that has been upgraded to the new Spring 10 release?

My class had not been set to Version 18.  Once I did that, it worked.




Opps.  Spoke too soon.


Once I changed to Version 18, it compiled without anything in the "Problems" tab.  Hence, i thought I was OK.  However, I just noticed that there is a red X error in the margin which has a popup tooltip reading:


expecting "from" found ''


That doesn't seem to make any sense to me.


Any clues? 


You have a bonus comma before your FROM:


SELECT CampaignId, AVG(Amount) test,  FROM Opportunity 


remove the comma after 'test'.


Thanks - don't know how I missed that.  Maybe that's what happens when you work too late at night.