You need to sign in to do that
Don't have an account?
Julio Hernandez
Pulling report with APEX controller
Hi,
I created an APEX controller which in theory should pull the data given by the report. Unfortunatly I dont think it's pulling the report at all. Here is the Controller Code.
I know it doesnt work because numberOfCases stays at zero even though the report has data in it.
I created an APEX controller which in theory should pull the data given by the report. Unfortunatly I dont think it's pulling the report at all. Here is the Controller Code.
public class reportData{ private static Integer LOWER = 4; private static Integer MID = 8; public String gaugeColor { get; set; } public class GaugeData { public String name { get; set; } public Integer size { get; set; } public GaugeData(String name, Integer size) { this.name = name; this.size = size; } } public List<GaugeData> data { get; set; } public reportData() { this.data = new List<GaugeData>(); List<Report> reportList = [ select Id, DeveloperName from Report where DeveloperName = 'Active_Solution_Hawks' ]; String reportId = (String)reportList.get(0).get('Id'); Reports.ReportResults results = Reports.ReportManager.runReport(reportId, true); Reports.Dimension dim = results.getGroupingsDown(); Integer numberOfCases = 0; for (Reports.GroupingValue groupingVal : dim.getGroupings()) { String factMapKey = groupingVal.getKey() + '!T'; Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails)results.getFactMap().get(factMapKey); Reports.SummaryValue sumVal = factDetails.getAggregates()[0]; numberOfCases += Integer.valueOf(sumVal.getLabel()); } this.data.add(new GaugeData('Cases', numberOfCases )); if (numberOfCases < LOWER) { this.gaugeColor = '#093, #ddd'; } else if (numberOfCases < MID) { this.gaugeColor = '#ff6, #ddd'; } else { this.gaugeColor = '#c00, #ddd'; } } }
I know it doesnt work because numberOfCases stays at zero even though the report has data in it.
Please refer to the similar example and modify it as per your requirement.
Apex Controller:
VisualForce Page:
To run the report from page: Set column values in table: Set row values :
Please mark this as solved if it helps.
Best Regards,
Nagendra.P
I too exactly need the one which you have given, so thanks for posting.
Anyways, I'm still getting the following error.
Visualforce Error:
System.NoDataFoundException: The data you’re trying to access is unavailable.
Error is in expression '{!runReport}' in component <apex:commandButton> in page runreport: Class.reports.ReportManager.runAsyncReport: line 33, column 1
Class.AsyncReportController.runReport: line 28, column 1
An unexpected error has occurred. Your solution provider has been notified. (reports)
Kindly let me know where I went wrong or what has to be modified.
Thanks,
Leafen.