I have a file to insert Accounts ,but some fields like account name have values with special characters like 'ñ' ,and Im having this error "BLOB is not a valid UTF-8 string" when I execute this query:

StaticResource srObject = [select id,body 
from StaticResource Where Name = 'NewAccountInsert'];
String contents = srObject.body.toString();

Any thoughts?


It appears that your file, at the time of upload, was encoded in some other encoding - perhaps ISO Latin-1 or Codepage 1252. All strings in Salesforce are required to be encoded in valid UTF-8.

Converting encodings in Apex is not supported natively. Instead, convert the file at the point of origin to UTF-8 encoding and upload that version. This is possible in many spreadsheet applications, or you can use a programmer's editor like Visual Studio Code to convert the file to UTF-8.

  • It worked perfectly with Visual Studio Code,thanks! Aug 24 '19 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.