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
Sandesh D GanjareSandesh D Ganjare 

Test Class for Reports.

Hi,
I am new salesforce. I wrote fro fetching the reports for reports schema and displaying on the VF page. I have Wrote method where  i am supplying report Id from where I get List of Ids present in the reports.
So can you help to write the test class for the same.

Apex Code:
/////////////////////////////////////////////////////
/*List<Report> lstReport = [Select id,name from Report where format = 'Tabular'];
List<Id> lstID = new List<Id>();
List<String> lstname = new List<String>();
if(lstReport != null)
{
  for(Report rpt : lstReport)
  {*/
    Id reportId ='00O28000004otCPEAY';// rpt.id;//rpt.id; //;
    //System.debug(rpt.name);    
    Reports.ReportResults  reportDescription = Reports.ReportManager.runReport(reportId,true);
    Reports.ReportFactWithDetails factWithDetails = (Reports.ReportFactWithDetails)reportDescription.getFactMap().get('T!T');
    Reports.ReportExtendedMetadata reportExtendedMetadata = reportDescription.getReportExtendedMetadata();
    //Reports.ReportMetadata reportMetadata = reportDescription.getReportMetadata();
    System.debug(reportExtendedMetadata.getDetailColumnInfo());
    Map<String,Reports.DetailColumn> reportDetailColumn = reportExtendedMetadata.getDetailColumnInfo();
    List<Integer> indexList = new List<Integer>();
    List<List<Integer>> indexListofList = new List<List<Integer>>();  
    Set<ID> setRecordIds = new Set<ID>();
    List<String> lstobjectAPIName = new List<String>();
    List<MapPointInfo> lstMapPointInfo = new List<MapPointInfo>();
    Integer idColumnindex = 0;
    for(Reports.DetailColumn columnValue : reportDetailColumn.values())
    {
      Reports.ColumnDataType columnDataType = columnValue.getDataType();
      Reports.ColumnDataType typeData = Reports.ColumnDataType.ID_DATA;
      if(columnDataType == (Reports.ColumnDataType.ID_DATA))
      {
       String Name =columnValue.getName();
       String Label= columnValue.getLabel();
       indexList.add(idColumnindex);
       System.debug(Name);
       System.debug(columnDataType);  
      }
      idColumnindex = idColumnindex + 1;
    }
    System.debug(indexList);
////////////////////////////////////////////////////    
    if(indexList != Null)
    {  
     for(reports.ReportDetailRow  row :  factWithDetails.getRows())
     {    
     for (Integer i = 0; i < indexList.size(); i++) 
     {
       Integer m = indexList[i];
       if((row.getDataCells()[m].getLabel())!= '-' && (row.getDataCells()[m].getLabel())!=null)
       {
          setRecordIds.add(row.getDataCells()[m].getLabel());   
       }
     } 
     }  
    System.debug(setRecordIds);
    System.debug(setRecordIds.size());    
   }

Thanks,
Sandesh G