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

Aggregate Function Type
I am trying to create a visualforce page that will show what % of a sales reps total funnel is represented by a given opportunity.
I have been working on the controller for this, but keep getting an error:
Error: Compile Error: Return value must be of type: Decimal at line 14 column 9 |
public class OpportunityExt { private final Opportunity opp; public OpportunityExt(ApexPages.StandardController stdController) { this.opp = (Opportunity)stdController.getRecord(); } public integer getOpenTasks() { return [SELECT count() FROM task WHERE whatid = :opp.id and IsClosed=false]; } public decimal getFunnel() { return [SELECT Sum(Amount) FROM opportunity WHERE ownerid = :opp.ownerid]; } }
I have also tried Integer, but I was under the impression that currency fields were stored as decimal...
Has anybody run into something like this before?
Aggregate Results are objects and you need to "get" the fields and cast the properly. The below does not account for an empty result
An example:
All Answers
Pleaes try to use the below code and let me know if that works. FYI... didn't test this out, but just thought AggregateResults
would work.
public decimal getFunnel() {
AggregateResult groupedResults = [SELECT Sum(Amount) FROM opportunity WHERE ownerid = :opp.ownerid];
return double.valueof(groupedResults);
}
Thanks!
Still getting "Content cannot be displayed: Invalid double: [AggregateResult (expr0:25118.0)]" in the visualforce page though...
Aggregate Results are objects and you need to "get" the fields and cast the properly. The below does not account for an empty result
An example:
Thank you so much!
Would it then be possible to perform another math function to that?
I am trying to reference 'Funnel' later in the code but it is not finding it.
return (decimal)ar.get('expr0'));
Replace last statement with this...