Trying to pull out a List of IDs from a matrix type report.
I think I understand Tabular and Summary type reports but I am lost on Matrix type. Here is my code:
private List<Reports.ReportDetailRow> getRowsFromTabular(Reports.ReportResults results) {
Reports.ReportFactWithDetails detailFact = (Reports.ReportFactWithDetails)results.getFactMap().get('T!T');
return detailFact.getRows();
}
private List<Reports.ReportDetailRow> getRowsFromSummary(Reports.ReportResults results) {
Reports.ReportFactWithDetails detailFact = (Reports.ReportFactWithDetails)results.getFactMap().get('0!T');
return detailFact.getRows();
}
private List<Reports.ReportDetailRow> getRowsFromMatrix(Reports.ReportResults results) {
Reports.ReportFactWithDetails detailFact = (Reports.ReportFactWithDetails)results.getFactMap().get('0!0');
return detailFact.getRows();
}
Tabular and Summary work great, however results for Matrix are wrong.
I only get some of the IDs.
I am sure that the problem is my use of the fact map selectors. However I can't figure out how to get them all. I have read and re-read the only document I can find from Salesforce about the Fact Map. Are there other tutorials or example of the Fact Map that I should understand?
Best Answer
This guide explains how to decode the fact map: https://resources.docs.salesforce.com/sfdc/pdf/salesforce_analytics_rest_api.pdf
Basically, the 0!0 you're getting is just the results of the first subtotal of the first grouping, and each grouping has subresults that you have to process to get the underlying data. Here's the relevant section of the docs: