You need to sign in to do that
Don't have an account?
Kerry Proksel
Issue Displaying AggregateResults on VisualForce page
Hi Community,
I am trying to make a Visualforce table that will hold summed amounts. I want to have eight different SOQL queries that all use the SUM function, and then display them in a Visualforce table.
Here's my controller so far:
public class PipelineController {
public list<AggregateResult> newBizAmt = new list<AggregateResult>();
public PipelineController(){
newBizAmt = [select SUM(Amount) nba,RecordTypeForm__c
from Opportunity
WHERE RecordTypeForm__c = 'New Business'
AND Current_Quarter__c = 'Q2-2016'
AND isClosed = FALSE
GROUP BY RecordTypeForm__c];
}
public list<WrpClass> getResults(){
list<WrpClass> nbaResults = new list <WrpClass>();
for(AggregateResult ba:newBizAmt){
WrpClass objwc = new WrpClass(ba);
nbaResults.add(objwc);
}
return nbaResults;
}
class WrpClass{
public Double Amount{get;set;}
public WrpClass(AggregateResult ba){
Amount=(Double)ba.get('nba');
}
}
}
I've been trying to display the result in a Visualforce page, but am having issues. Here's what I have:
<apex:page controller="PipelineController">
<apex:pageBlock title="Sales Pipeline">
<apex:pageBlockTable value ="{!results}" var="item">
<apex:column value="{!nbaResults"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Could anyone help point me in the right direction? I know my column value is incorrect, but I'm not sure what to edit to make it work. Any help would be appreciated.
I am trying to make a Visualforce table that will hold summed amounts. I want to have eight different SOQL queries that all use the SUM function, and then display them in a Visualforce table.
Here's my controller so far:
public class PipelineController {
public list<AggregateResult> newBizAmt = new list<AggregateResult>();
public PipelineController(){
newBizAmt = [select SUM(Amount) nba,RecordTypeForm__c
from Opportunity
WHERE RecordTypeForm__c = 'New Business'
AND Current_Quarter__c = 'Q2-2016'
AND isClosed = FALSE
GROUP BY RecordTypeForm__c];
}
public list<WrpClass> getResults(){
list<WrpClass> nbaResults = new list <WrpClass>();
for(AggregateResult ba:newBizAmt){
WrpClass objwc = new WrpClass(ba);
nbaResults.add(objwc);
}
return nbaResults;
}
class WrpClass{
public Double Amount{get;set;}
public WrpClass(AggregateResult ba){
Amount=(Double)ba.get('nba');
}
}
}
I've been trying to display the result in a Visualforce page, but am having issues. Here's what I have:
<apex:page controller="PipelineController">
<apex:pageBlock title="Sales Pipeline">
<apex:pageBlockTable value ="{!results}" var="item">
<apex:column value="{!nbaResults"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Could anyone help point me in the right direction? I know my column value is incorrect, but I'm not sure what to edit to make it work. Any help would be appreciated.
Here's the updated code (with an extra query):
public with sharing class PipelineController {
public list<AggregateResult> newBizAmt = new list<AggregateResult>();
public list<AggregateResult> newExpAmt = new list<AggregateResult>();
public PipelineController(){
newBizAmt = [select SUM(Amount) nba, SUM(ExpectedRevenue) expRevenue, RecordType.Name
from Opportunity
WHERE RecordTypeForm__c = 'New_Business'
AND Current_Quarter__c = 'Q2-2016'
AND isClosed = FALSE
GROUP BY RecordType.Name];
newExpAmt = [select SUM(ExpectedRevenue) expRevenue
from Opportunity
WHERE RecordTypeForm__c = 'New_Business'
AND Current_Quarter__c = 'Q2-2016'
AND isClosed = FALSE ];
}
public list<WrpClass> getResults(){
list<WrpClass> nbaResults = new list <WrpClass>();
for(AggregateResult ba:newBizAmt){
WrpClass objwc = new WrpClass(ba);
nbaResults.add(objwc);
}
return nbaResults;
}
class WrpClass{
public Double Amount{get;set;}
public Double AmountTwo{get;set;}
public WrpClass(AggregateResult ba){
Amount=(Double)ba.get('nba');
AmountTwo=(Double)ba.get('expRevenue');
}
}
}
Here's the VF:
<apex:page controller="PipelineController">
<apex:pageBlock title="Sales Pipeline">
<apex:dataTable value ="{!results}" var="m">
<apex:column value="{!m.Amount}"/>
<apex:column value="{!m.AmountTwo}"/>
</apex:dataTable>
</apex:pageBlock>
</apex:page>
All Answers
Try: <apex:column value="{!item.Amount}" /> to display the amount as a table column.
Here's the updated code (with an extra query):
public with sharing class PipelineController {
public list<AggregateResult> newBizAmt = new list<AggregateResult>();
public list<AggregateResult> newExpAmt = new list<AggregateResult>();
public PipelineController(){
newBizAmt = [select SUM(Amount) nba, SUM(ExpectedRevenue) expRevenue, RecordType.Name
from Opportunity
WHERE RecordTypeForm__c = 'New_Business'
AND Current_Quarter__c = 'Q2-2016'
AND isClosed = FALSE
GROUP BY RecordType.Name];
newExpAmt = [select SUM(ExpectedRevenue) expRevenue
from Opportunity
WHERE RecordTypeForm__c = 'New_Business'
AND Current_Quarter__c = 'Q2-2016'
AND isClosed = FALSE ];
}
public list<WrpClass> getResults(){
list<WrpClass> nbaResults = new list <WrpClass>();
for(AggregateResult ba:newBizAmt){
WrpClass objwc = new WrpClass(ba);
nbaResults.add(objwc);
}
return nbaResults;
}
class WrpClass{
public Double Amount{get;set;}
public Double AmountTwo{get;set;}
public WrpClass(AggregateResult ba){
Amount=(Double)ba.get('nba');
AmountTwo=(Double)ba.get('expRevenue');
}
}
}
Here's the VF:
<apex:page controller="PipelineController">
<apex:pageBlock title="Sales Pipeline">
<apex:dataTable value ="{!results}" var="m">
<apex:column value="{!m.Amount}"/>
<apex:column value="{!m.AmountTwo}"/>
</apex:dataTable>
</apex:pageBlock>
</apex:page>