You need to sign in to do that
Don't have an account?

Error on SOQL
Hi,
I've write a query on opportunity to see avg amount.
How can i see avg amount of opportunity.
Error:line 1, column 1: Illegal assignment from LIST to LIST
List<Opportunity> lst = [SELECT AVG(Amount) FROM Opportunity];
Hi,
Try the below code snippet as reference:
AggregateResult[] groupedResults = [SELECT AVG(Amount)aver FROM Opportunity];
system.debug('!!!!!!!'+groupedResults[0].get('aver'));
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi Navatar,
Could you explain why are we using "AggregateResult[] groupedResults" instead of collection for quering.
Please Provide me reference links
Hey Shravan,
You have to remeber that SOQL is not SQL, so the AVG() function in your query does not work the same way as you would in SQL.
What Ankit posted was using Aggregate functions in a query. Aggregate functions are used to perform operations like sum, avg, count and others. These follow a specific syntax different from a normal SOQL query. You can read more on them at
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm
Thanks,
Jerun Jose