function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul Kumar 96Rahul Kumar 96 

CSV with special character

I am facing some issue reading CSV file from email attachment:

CSV attachments containing any special character gives me invalid BLOB error. ( My attachments contains  " é "  French character  and similar keywords.)
 
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();     
        if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {        
            for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
                Blob fileContent = email.binaryAttachments[i].body;
               String[] elements = fileContent.toString().split(';|\n');

 
Exception:    StringException: BLOB is not a valid UTF-8 string

Thanks,
Rahul
Donald BlayDonald Blay
You should be able to use the EncodingUtil.urlEncode() method and pass it  'UTF-8' as the 2nd parameter.

blobString = EncodingUtil.urlEncode(originalString, 'UTF-8');

For more information check out https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_encodingUtil.htm

 
Naveen KNNaveen KN
Check the below link
https://www.codengine.in/2019/06/blob-is-not-a-valid-utf-8-string-salesforce-apex.html