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

  • What happens if you wrap your component in visualforce page and open as is. Is there any data? – kurunve May 29 '17 at 11:55
  • yes, in report data exist. i need to fetch those data, but getcontent() not working. – Ratika 123 May 31 '17 at 7:09
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';
|improve this answer|||||

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.