I have an excel/csv as an attachment related to an EmailMessage. I want to read the csv, process the data and create certain records(of custom object) based on that data. I want to understand how I can read the attachment using apex?
What I am trying to do is, get the information from an attachment.
Attachment attachmentRecord = [Select Id,Body,ContentType from Attachment WHERE ParentId =<my EmailMessageId>]; System.debug('a ' +attachmentRecord.Body); System.debug('b '+attachmentRecord.Body.toString());
When I print the body, I get the output as :
if I convert it to string(2nd debug statement) I get an error saying :
System.StringException: BLOB is not a valid UTF-8 string
I want to understand what am I doing wrong here.