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
AQAQ 

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?

 

Thanks. 

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

All Answers

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

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

 

Thanks! 

AQAQ

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? 

bob_buzzardbob_buzzard

You have a bonus comma before your FROM:

 

SELECT CampaignId, AVG(Amount) test,  FROM Opportunity 

 

remove the comma after 'test'.

 

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