• Hamayoun Khan 5
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi, has the developer keynote for DF15 been uploaded?
Hi, has the developer keynote for DF15 been uploaded?
Hi Everyone,

I found a great solution online which allows to email a report from SF to non-SF users - http://kevindotcar.wix.com/home/apps/blog/how-to-schedule-a-report-to-send

This worked great until the report had non-english characters which is causing an issue.

VF email template is used and when the report has non-english characters, it displays the error message of "Error occurred trying to load the template for preview: BLOB is not a valid UTF-8 string. Please try editing your markup to correct the problem." at the top of the page.

Here's the code for VF 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="00OR0000000kUFo"/>
</messaging:attachment>
</messaging:emailTemplate>
Here's the code for ReportExportController.

<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>
Here's the code for CSVStream.
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 );
    }

}
Does anybody have an idea how to fix this?

Appreciate your help in advance!!



  • September 19, 2014
  • Like
  • 0