function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ross Gilbert 19Ross Gilbert 19 

Why am I getting this error

public Static List<List> getTabularReport(Id reportId) {

I am getting an error for that line: Error: Compile Error: expecting a left angle bracket, found '>'

Does anyone know what is wrong with the syntax in that line of code?  Thanks a lot
Neetu_BansalNeetu_Bansal
Hi Ross,

List is not any type, and you may need to use primitive or object types in list like:
public Static List<String> getTabularReport(Id reportId) {
You can use your defined type instead of string here. Let me know, if you need any other help.

Thanks,
Neetu
Ross Gilbert 19Ross Gilbert 19
Thanks.  Yeah that is what I thought but I'm having trouble with this code.  Here is the non working code.  Not sure how to fix this.  The code below cannot be saved in SFDC as a new class.  If you try to save it in SFDC as a new class you'll get the error I'm talking about.  Thanks a lot for your help.
 
public with sharing class AnalyticsUtils {

    public Static List<List> getTabularReport(Id reportId) {
        List<List> rowList = new List<List>();

        //get the report result
        Reports.ReportResults results = Reports.ReportManager.runReport('00Oj0000003OHhw', true);

        //get the metadata
        Reports.ReportMetadata reportMetadata = results.getReportMetadata();

        //get a string array of the field names
        List fieldNames = reportMetadata.getDetailColumns();

        // Get the fact map from the report results
        Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails)results.getFactMap().get('T!T');     

        List reportDetailRowList = factDetails.getRows();

        //add the field names as the first row
        rowList.add(fieldNames);

        //loop over the rows
        for (Reports.ReportDetailRow reportDetailRow: reportDetailRowList) {
            List cellList = new List();
            //loop over the cells in the row
            for (Reports.ReportDataCell reportDataCell: reportDetailRow.getDataCells()) {
                cellList.add(reportDataCell.getLabel());        
            }

            //add the row to the list
            rowList.add(cellList);
        }

        return rowList;
    }

}

 
Neetu_BansalNeetu_Bansal
Hi Ross,

Try with the below code:
public with sharing class AnalyticsUtils {

    public Static List<String> getTabularReport(Id reportId) {
        List<String> rowList = new List<String>();

        //get the report result
        Reports.ReportResults results = Reports.ReportManager.runReport('00Oj0000003OHhw', true);

        //get the metadata
        Reports.ReportMetadata reportMetadata = results.getReportMetadata();

        //get a string array of the field names
        List<String> fieldNames = reportMetadata.getDetailColumns();

        // Get the fact map from the report results
        Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails)results.getFactMap().get('T!T');     

        List<String> reportDetailRowList = factDetails.getRows();

        //add the field names as the first row
        rowList.addAll(fieldNames);

        //loop over the rows
        for (Reports.ReportDetailRow reportDetailRow: reportDetailRowList) {
            List<String> cellList = new List<String>();
            //loop over the cells in the row
            for (Reports.ReportDataCell reportDataCell: reportDetailRow.getDataCells()) {
                cellList.add(reportDataCell.getLabel());        
            }

            //add the row to the list
            rowList.addAll(cellList);
        }

        return rowList;
    }

}
List is a keyword, and you need to define the type of list here.

Let me know, if you need any other help.

Thanks,
Neetu
Ross Gilbert 19Ross Gilbert 19
Thanks a lot.  Yeah I think I tried that earlier but maybe not.  Anyway when I try with your revised code I get this error:

Error: Compile Error: Illegal assignment from List<reports.ReportDetailRow> to List<String>
Neetu_BansalNeetu_Bansal
Hi Ross,

Your class code is dependent on other class Reports and its inner classes, To help you out, I need to check code for these classes too. Can you share your salesforce org login credentials so I'll be able to help you out. You can contact me either on my gmail id: neetu.bansal.5@gmail.com or Skype id: neetu.bansal.5

Thanks,
Neetu
Abhishek BansalAbhishek Bansal

Hi Ross,

Please change your line 18 i.e. : List<String> reportDetailRowList = factDetails.getRows();

To : List<Reports.ReportDetailRow> reportDetailRowList = factDetails.getRows();

Regards,
Abhishek