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
Afroz Khan 8Afroz Khan 8 

Can someone help me with the test class for the below apex class

@AuraEnabled(cacheable = true)
public static String colorbox() {
List <Report> reportList = [SELECT Id,DeveloperName FROM Report where DeveloperName = 'test_report'];
String reportId = (String)reportList.get(0).get('Id'); Reports.ReportDescribeResult reportInfo = Reports.ReportManager.describeReport(reportId); Reports.ReportExtendedMetadata reportMeta = reportInfo.getReportExtendedMetadata(); Map<String, Reports.DetailColumn> columnData = reportMeta.getDetailColumnInfo(); for(Reports.DetailColumn column: columnData.values()) { System.debug(column.getName()); System.debug(column.getLabel()); } // Get the report metadata Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId); System.debug('describe: ' + describe); Reports.ReportMetadata reportMd = describe.getReportMetadata(); System.debug('reportMd: ' + reportMd); // Override filter and run report Reports.ReportFilter filter = reportMd.getReportFilters()[0]; System.debug('filter: ' + filter); Reports.ReportResults results = Reports.ReportManager.runReport(reportId, reportMd); System.debug('results: ' + results); Reports.ReportFactWithSummaries factSum = (Reports.ReportFactWithSummaries)results.getFactMap().get('0!0'); System.debug('Value for November: ' + factSum.getAggregates()[0].getLabel()); String LateRecord = (string)factSum.getAggregates()[0].getLabel(); system.debug('LateRecord='+LateRecord); @testVisible Integer i = integer.valueof(LateRecord); system.debug('i='+i); if(i > 2) { //red return 'TRUE'; } //green return Null; }
Afroz Khan 8Afroz Khan 8
public class lwc_jfworkspacecolorbox {
    
    @AuraEnabled(cacheable = true)
    public static String colorbox()
    {
        List <Report> reportList = [SELECT Id,DeveloperName FROM Report where
                                     DeveloperName = 'test_reprort'];
        String reportId = (String)reportList.get(0).get('Id');
        
        Reports.ReportDescribeResult reportInfo = Reports.ReportManager.describeReport(reportId);
        Reports.ReportExtendedMetadata reportMeta = reportInfo.getReportExtendedMetadata();
        Map<String, Reports.DetailColumn> columnData = reportMeta.getDetailColumnInfo();
        for(Reports.DetailColumn column: columnData.values()) {
            System.debug(column.getName());
            System.debug(column.getLabel());
        }
        
        // Get the report metadata
        Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId);
        System.debug('describe: ' + describe);
        Reports.ReportMetadata reportMd = describe.getReportMetadata();
        System.debug('reportMd: ' + reportMd);        
        // Override filter and run report
        Reports.ReportFilter filter = reportMd.getReportFilters()[0];
        System.debug('filter: ' + filter);
        Reports.ReportResults results = Reports.ReportManager.runReport(reportId, reportMd);
        System.debug('results: ' + results);
        
        
        Reports.ReportFactWithSummaries factSum =
            (Reports.ReportFactWithSummaries)results.getFactMap().get('0!0');
        System.debug('Value for November: ' + factSum.getAggregates()[0].getLabel());
        String LateRecord = (string)factSum.getAggregates()[0].getLabel();
        system.debug('LateRecord='+LateRecord);
       
       @testVisible
       Integer i = integer.valueof(LateRecord);
         system.debug('i='+i);
        if(i > 2)
        {
            //red
            return 'TRUE';
        }
        //green
         return Null;
    }

}