You need to sign in to do that
Don't have an account?
sai harish
Invalid field for AggregateResult, Please help - Its urgent !!
Hello,
I am trying to use a wrapper class to show some values in a HTML table. I am trying to use Revenue and Revenue1 in the page. My page saves fine but when I try to preview, I am getting the following error, Invalid field rev for AggregateResult. When I try to use the Name field, it works fine.
Here is my class. Any help is appreciated.
I am trying to use a wrapper class to show some values in a HTML table. I am trying to use Revenue and Revenue1 in the page. My page saves fine but when I try to preview, I am getting the following error, Invalid field rev for AggregateResult. When I try to use the Name field, it works fine.
Public Class SalesBudgetReport1{ Public List<RevenueForecast> RevenueForecasts {get; set;} Public SalesBudgetReport1(){ List<AggregateResult> arList = new List<AggregateResult>(); List<AggregateResult> ar = [Select PM__c PM, 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 PM, 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 PM, 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]; List<AggregateResult> ar3 = [Select PM__c PM, sum(Revenue__c) revenue3 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 4 Group By PM__c]; List<AggregateResult> ar4 = [Select PM__c PM, sum(Revenue__c) revenue4 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 5 Group By PM__c]; List<AggregateResult> ar5 = [Select PM__c PM, sum(Revenue__c) revenue5 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 6 Group By PM__c]; List<AggregateResult> ar6 = [Select PM__c PM, sum(Revenue__c) revenue6 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 7 Group By PM__c]; List<AggregateResult> ar7 = [Select PM__c PM, sum(Revenue__c) revenue7 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 8 Group By PM__c]; List<AggregateResult> ar8 = [Select PM__c PM, sum(Revenue__c) revenue8 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 9 Group By PM__c]; List<AggregateResult> ar9 = [Select PM__c PM, sum(Revenue__c) revenue9 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 10 Group By PM__c]; List<AggregateResult> ar10 = [Select PM__c PM, sum(Revenue__c) revenue10 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 11 Group By PM__c]; List<AggregateResult> ar11 = [Select PM__c PM, sum(Revenue__c) revenue11 from Revenue_Forecast__c WHERE PM__c!= null AND calendar_year(Forecast_Date__c ) = 2018 AND calendar_month(Forecast_Date__c ) = 12 Group By PM__c]; arList.addAll(ar) ; arList.addAll(ar1) ; arList.addAll(ar2) ; arList.addAll(ar3) ; arList.addAll(ar4) ; arList.addAll(ar5) ; arList.addAll(ar6) ; arList.addAll(ar7) ; arList.addAll(ar8) ; arList.addAll(ar9) ; arList.addAll(ar10) ; arList.addAll(ar11) ; RevenueForecasts = new List<RevenueForecast>(); for(AggregateResult arr : arList){ 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'); Revenue = (Decimal) arr.get('rev'); Revenue1 = (Decimal) arr.get('revenue1'); } } }
Here is my class. Any help is appreciated.
I am still getting the same error. Invalid field for AggregateResult. I can't understand what I am missing. Here is my code for the page.
I am still getting the same error.
I tried to debug everything. I am able to see individual values from ar to ar11.
Then I tried to debug arList. It has only values from ar, ar1, ar2, ar3.