0

I'm trying to create a csv file attached to a visualforce email template. When i comment "strOut = new PageReference(requestURL).getContent().toString(); " then it generate a CSV file with no data. Any suggestion please.

Vf Component:-

<apex:component controller="CSVStream" access="global">
<apex:attribute name="xstrRptname" description="report ID" type="String" assignTo="{!strRptname}"/>
<apex:outputText value="{!CSVStream}" escape="false"/>
</apex:component>

Controller :-

public class CSVStream {
public static Boolean isTest;
public static String strEmailAddr;
public static String strOut;
public static Boolean restRequested;
public String strEmail{get;set;}
public String strRptname{get;set;}

void CSVStream () {
    strOut = '';        
    }

public String getCSVStream() {
    restRequested = System.isFuture() || System.isScheduled();
    executeRpt();
    return strOut;
    }

public void executeRpt() {
    String requestURL;
    requestURL = '/' + strRptname + '?csv=1&exp=1';
    strOut = new PageReference(requestURL).getContent().toString();
    System.debug('CALLING executeRpt:  output= ' + strOut );
}

}

Vf Email Template:-

 <messaging:emailTemplate subject="Data Export" recipientType="User" >
 <messaging:plainTextEmailBody >

 Hi,

  please find attached the report(s) you have requested...

  Kind regards,
  {!$Organization.Name}
  </messaging:plainTextEmailBody>

  <messaging:attachment filename="report.csv" >
  <c:ReportExportController xstrRptname="00OP0000000Jp3N"/>
  </messaging:attachment>
  </messaging:emailTemplate>

Please help!

Thanks

2
  • What happens if you wrap your component in visualforce page and open as is. Is there any data?
    – kurunve
    Commented May 29, 2017 at 11:55
  • yes, in report data exist. i need to fetch those data, but getcontent() not working.
    – Ratika 123
    Commented May 31, 2017 at 7:09

1 Answer 1

0

try to use following params in your requestURL String within the controller:

?export=1&enc=UTF-8&xf=csv

So it would be:

requestURL = '/' + strRptname + 'export=1&enc=UTF-8&xf=csv';

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .