You need to sign in to do that
Don't have an account?
IP
how to resolve "Illegal assignment from LIST<AggregateResult> to Decimal" error
Hi, I'm trying to assign a result of a query to a variable. but i cannot do like that. following is my code.
Public decimal Revenue=[select sum(amount) from opportunity];
it throws an error as "Illegal assignment from LIST<AggregateResult> to Decimal "..
I've also tried with double instead of decimal. it doesn't work.
Please give me a solution for my scenario.
Try this and let me know if it doesn't work for you.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
All Answers
when you are trying to aggregate a field like sum(field name) that must be the result of aggregate result object..smiply like this
AggregateResult[] groupedResults= [SELECT AVG(Amount)aver FROM Opportunity];
Try this and let me know if it doesn't work for you.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
When I try this I get the following error:
Save error: line 4:82 no viable alternative at character ''
Thanks for your help!
I keep getting an error anytime no records are found by the SOQL query. My debug log shows me that even for empty queries, the size of groupedResults is 1 -- so the if statement checking for size > 0 isn't catching the null exceptions for me.
Any ideas? Thanks in advance.