You need to sign in to do that
Don't have an account?
sai harish
Need help with Wrapper Class for AggregateResult queries
Hello,
I am trying to use a HTML table and I need to show some values by each month. I am planning to use 12 queries, 1 for each column. I can use only 1 apex:repeat for the table to maintain consistency in the table. I am kind of a beginer in salesforce. I am not understanding how to wrap all these queries with 1 wrapper class. I am attaching a screenshot of what I am looking for. Any help is Appreciated !!
I am trying to use a HTML table and I need to show some values by each month. I am planning to use 12 queries, 1 for each column. I can use only 1 apex:repeat for the table to maintain consistency in the table. I am kind of a beginer in salesforce. I am not understanding how to wrap all these queries with 1 wrapper class. I am attaching a screenshot of what I am looking for. Any help is Appreciated !!
Public Class SalesBudgetReport1{ Public List<RevenueForecast> RevenueForecasts {get; set;} Public SalesBudgetReport1(){ List<AggregateResult> ar = [Select PM__c, sum(Revenue__c) rev from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 1 Group By PM__c]; List<AggregateResult> ar1 = [Select PM__c, sum(Revenue__c) revenue1 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 2 Group By PM__c]; List<AggregateResult> ar2 = [Select PM__c, sum(Revenue__c) revenue2 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 3 Group By PM__c]; RevenueForecasts = new List<RevenueForecast>(); for(AggregateResult arr : ar){ RevenueForecasts.add(new RevenueForecast(arr)); }} Public class RevenueForecast{ Public String Name {get; set;} Public Decimal Revenue{get; set; } Public Decimal Revenue1{get; set; } Public RevenueForecast(AggregateResult arr){ Name = (String) arr.get('PM__c'); Revenue = (Decimal) arr.get('rev'); }}}
Thank you fo the reply. I am able to show the names. My problem is with showing values from ar1 and ar2. I am not understanding if I have to use a different method for each query or if I can do it in the same method ? When I try to do this, it is giving me an error saying method already defined. Can I do it in one method ? I am confused.
Thanks.
Sai.
Here is my Apex class and VF page. I need to use 12 different queries and each query has to go in to 1 <td>. Thank you for all the help Raj !!
Thank you for the reply. I tried to use your code. My Apex class and VF page saved fine. I used Revenue and Revenue1 which are in line 49 and 52, the page saved fine, when I try to preview, it said invalid field rev. so I removed that for loop and tried to used Revenue1. I am getting the same error. Any further ideas and help is appreciated.
Thanks.
Sai.