+ Start a Discussion
MSongMSong 

"BLOB is not a valid UTF-8 string" Issue

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!!



Best Answer chosen by MSong
SFDC HedgehogSFDC Hedgehog
Hi mSong,

I know I'm answering late, and you prolly figured it out, but on this line;
requestURL = '/' + strRptname + '?csv=1&exp=1';

Change it to:
 
requestURL = '/' + strRptname + '?csv=1&exp=1&enc=UTF-8';

All Answers

SFDC HedgehogSFDC Hedgehog
Hi mSong,

I know I'm answering late, and you prolly figured it out, but on this line;
requestURL = '/' + strRptname + '?csv=1&exp=1';

Change it to:
 
requestURL = '/' + strRptname + '?csv=1&exp=1&enc=UTF-8';
This was selected as the best answer
MSongMSong
Hi Kevin - Actually, I couldn't figure it out (I'm not a developer) but I'm very glad you answered my question. I tested it and it works like magic. Thank you!!
SFDC HedgehogSFDC Hedgehog
Thanks mSong

Glad to help!
 
Hamayoun Khan 5Hamayoun Khan 5
Hi Hedgehog

Thank you so much, I was using the same code as mSong and ran into the same issue!
Mike Lippman 2Mike Lippman 2
I too would like to use this great utility.  But its a managed package.  So how were you able to edit the Apex class CSVStream?