用 Apex Code 抓出 Report Data 來跑迴圈
範例背景
Sample Code
// Run a report synchronously
String ReportId = '00O4T000001rt0ZUAQ';
Reports.reportResults Results= Reports.ReportManager.runReport(ReportId, true);
Results.getAllData();
System.debug('Value of Results.getAllData()' + Results.getAllData());
//system.debug(Results.getFactMap());
// Get the fact map from the report results
Reports.ReportFactWithDetails factDetails =
(Reports.ReportFactWithDetails)Results.getFactMap().get('0_0!T');
//create a list of report rows and populate it with the result rows from fact map
List<Reports.ReportDetailRow> reportRows = factDetails.getRows();
System.debug('Value of reportRows.size()' +reportRows.size());
List<Id> AccountIds = new List<Id>();
for(Reports.ReportDetailRow reportRow: reportRows){
List<Reports.ReportDataCell> datacells = reportRow.getDataCells();
Reports.ReportDataCell datacell = datacells[0];
system.debug(datacell.getvalue());
AccountIds.add((Id)datacell.getvalue());
}
留言
張貼留言