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