I am working on a requirement where i have a page where user will select from due date,to due date,received from date,received to date and report type based on these criterias the data should be rendered on pdf and excel.But i am not able to display the data in both. Please help me.

Below is the code that i have tried.

 public class PrivateEquityReport
   public Boolean isXLS {get;set;} 
   public List<Fund_Equity__c> activityRecords;
   public String displayPrivateEquity = '';

   ApexPages.StandardSetController regionStandardSetController{get;set;}

   public PrivateEquityReport()
        activityRecords= new list<Fund_Equity__c>();
        regionStandardSetController=new ApexPages.StandardSetController(new  list<Fund_Equity__c>());
        String reportType =          System.currentPageReference().getParameters().get('reportType');
         isXLS = true;
         isXLS = false;    


   String baseQuery  = 'SELECT '+''+'Id,Due_Date__c,Fund__r.Name,Company__r.Name,Subject__c,Comments__c,Date_Received__c,Business_Review__c,Attorney_Review__c '+''+'FROM Fund_Equity__c WHERE Team__c=\'Equity\' AND RecordType.Name=\'Amendment\'';

   public String getReportText()


   String checkQuery = baseQuery;

   String reportFromDateVar= System.currentPageReference().getParameters().get('dFromDate');
   Date fromDateVar = null;
   if(reportFromDateVar != null)
   fromDateVar = Date.valueOf(reportFromDateVar);
   System.debug('*****From Date***'+fromDateVar );

   String reportToDateVar =System.currentPageReference().getParameters().get('dToDate');
   Date toDateVar = null;
   if(reportToDateVar != null)
   toDateVar = Date.valueOf(reportToDateVar );
   System.debug('*****To Date***'+toDateVar );

   String reportReceiveFromDateVar= System.currentPageReference().getParameters().get('rFromDate');
   Date receivefromDateVar = null;
   if( reportReceiveFromDateVar != null)
   receivefromDateVar = Date.valueOf( reportReceiveFromDateVar);
   System.debug('*****Receive From Date***'+receivefromDateVar );

   String  reportReceiveToDateVar = System.currentPageReference().getParameters().get('rToDate');
   Date receivetoDateVar = null;
   if( reportReceiveToDateVar != null)
   receivetoDateVar = Date.valueOf( reportReceiveToDateVar );
   System.debug('****Receive To Date***'+receivetoDateVar );

   if((fromDateVar!= null)&&(toDateVar!=null))
    checkQuery =checkQuery  +' '+'and (Due_Date__c>=:fromDateVar AND Due_Date__c<= :toDateVar )';
    system.debug('************3'+checkQuery  );

   if((receivefromDateVar != null)&&(receivetoDateVar !=null))
    checkQuery  =checkQuery+' '+'and (Date_Received__c>=:receivefromDateVar AND Date_Received__c<= :receivetoDateVar )';
    system.debug('************3'+checkQuery  );

   regionStandardSetController=new ApexPages.StandardSetController(Database.getQueryLocator(checkQuery));

     activityRecords= regionStandardSetController.getRecords();
     // System.debug('*****records*****'+activityRecords);

      displayPrivateEquity ='<table><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr></table>' + displayPrivateEquity ;                
      displayPrivateEquity =    prepareReportSinglePagePrivateEquity(activityRecords,displayPrivateEquity );

     displayPrivateEquity  = prepareReportSinglePagePrivateEquity(activityRecords,displayPrivateEquity );
     displayPrivateEquity +='<DIV style="page-break-after:always"></div>';  
     return  displayPrivateEquity;

  Public String prepareReportSinglePagePrivateEquity(List<Fund_Equity__c>    fundListVar, String reportString)

    reportString+='<table width="100%" table-layout:"fixed" style="font-family: sans-serif;font-size: 12px" border="1" cellspacing="0" cellpadding="2">';
    reportString+='<tr align="left" style="background-color:#C0C0C0; color: ;"><th width="5%">'+'Due Date</th>'+'<th>'+'Fund</th>'
              +'<th width="5%">'+'Company</th>'+'<th width="5%">'+'Subject</th>'
              +'<th>'+'Comments</th>'+'<th>'+'Date Received</th>'
              +'<th>'+'Business Review </th>'+'<th width="5%">'+'Attorney Review</th></tr>';




I am calling in pdf visualforce as below

<apex:page controller="PrivateEquityReport" renderas="pdf"  applyHtmlTag="false" showHeader="false">

 <apex:outputLabel escape="false" value="{!reportText}">

Excel visualforce page.

<apex:page controller="PrivateEquityReport" contentType="application/vnd.ms-excel#PrivateEquityReport.xls" sidebar="false" showheader="false" cache="true">
   <apex:outputLabel escape="false" value="{!reportText}">


  • 2
    Create two different page with RenderedAs parameter as PDF and content type as contentType="application/x-excel#RenderAsTestFile.xls. Add these two pages as iFrame to original page. – Salesforcesmarty Feb 24 '16 at 4:57
  • Hi Salesforcesmarty,Thanks for the reply.I have created excel visualforce page also...I have updated it in my question above.I am not able to display the data in the pdf and excel the table is blank...i might have done some wrong in the controller..Please check it and please suggest me. – Learner_sfdc Feb 24 '16 at 5:07
  • Are you trying to display "reportString" in your page? If yes, then you need to fetch it in your VF page the way you have done for "reportText". – Shailesh Deshpande Feb 24 '16 at 5:58

So, here is where I think you are going wrong

  1. The VF page fetches the value of {!reportText} from the controller
  2. The controller method getReportText() is called
  3. The method returns void

So nothing is displayed. The method needs to return String and the value returned looks like it should be displayPrivateEquity

| improve this answer | |
  • Hi crop1645, Does it mean i have to make the return type of getReportText() method as String? Thanks – Learner_sfdc Feb 24 '16 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.