Have you encountered ‘BLOB is not a valid UTF-8 string’ issue while working on document parsing in the salesforce lightning?
Well, it may be because of multiple reasons. In this post, we will discuss one
of the root causes.
Apex decoding logic works well and good when the input Blob is in the correct format. In case if you try to upload xlsx document,
it will throw an error in the apex because of special characters in the text format. You can notice by opening xlsx file in the notepad as a text which shows special characters.
Please don't ask me to read that file for you. 😃
The below screenshot shows Apex error in the Salesforce logs window.
As a next step, change the format of the file with the below
steps.
Open the xlsx file, click on File > Save
as and enter the file name, select format as CSV (comma delimited) > click Save
Try to import the CSV file and test upload functionality.
I hope it resolved your issue. Thank you for using our services. In case if anything else solved your issue, appreciate your time to post it in the comments section below.
You may also like
4 Comments
Shouldn't we select the format as "CSV UTF-8" ?
ReplyDeleteSometimes even in the csv files encoding other than UTF-8 can be present like ANSI.
I think it works for CSV UTF-8 format as well.
DeleteHi, am decoding base64 encoded string. The string format is ?utf-8?b?QW5vbWFseSBkZXRIY3Rpb24g4oCTIERFIFNIQVc?=
ReplyDeleteDecoding is working fine in apex class but when am trying to insert record in test class am getting the error : blob is not valid utf-8 string.
Could you pls help
After decoding, are you mapping the decoded text to any field? And which object record you are inserting? Please share the code of test class method
Delete