+ Start a Discussion
KushiKushi 

Convert Reports to pdf and send email

I hae an apex class that converts the reports to a pdf and sends an email to the user.

Here is the Apex Class -
public class ReportChartController{

    public String reportId { get; set; }

    public List<Report> reportIdList {get;set;}
    
    public List<SelectOption> reportOptionList {get;set;}
    
    //retrive list of reports
    public ReportChartController(){
        reportIdList = new List<Report>();
        reportOptionList = new List<SelectOption>();
        for(Report rpt : [select Id,Name,FolderName from Report where FolderName='Print Folder']){
            System.debug('Report Name :'+rpt.Name);
            reportIdList.add(rpt);
            reportOptionList.add(new SelectOption(rpt.Id,rpt.Name));
        }
    }
        
    public PageReference reportSelectionChange(){
        System.debug('Selected Report '+reportId);
        String url = '/apex/ReportPDF?rptid='+reportId;
        PageReference pageRef = new PageReference(url);
        pageRef.setRedirect(false);
        return new PageReference(url);
    }
    
    public void sendEmail(){
        String email = UserInfo.getUserEmail();
        System.debug('Report ID :'+reportId+' Email: '+email);
        ReportUtils.sendReportExcelAttachment(reportId, email);
    }
    
    public void emailPDF(){
        String email = 'test@usbank.com';
        System.debug('Report ID :'+reportId+' Email: '+email);
        ReportUtils.sendReportPDFAttachment(reportId, email);
    }    
  }

Can someone help me in completing the test class.

Here is the test class-
​@isTest
public class ReportChartController_Test {
    
    static testMethod void reportSelectionChange()
    {
        test.startTest();
        List<Report> report_Obj  =  [SELECT Id,FolderName,Name from Report];
       // System.assertEquals(true,report_Obj.size()>0);
        ReportChartController rc = new ReportChartController();
        rc.reportId = (String)report_Obj.get(0).get('Id');
        rc.reportIdList = report_Obj;
        rc.reportOptionList = new List<SelectOption>();
              
        rc.reportSelectionChange();
      //  rc.sendEmail();
       // rc.emailPDF();
        test.stopTest();     
    }
  }

Thanks,
Kushi