0

Unable to convert from Blob to String. Can you please suggest how to convert to string. im getting some characters like this---> ��ࡱ�

1
  • Can you add the code thats causing this issue?
    – RedDevil
    Commented Jul 5, 2018 at 12:22

1 Answer 1

3

This is almost certainly a text encoding issue.

String values in Salesforce are always encoded in the UTF-8 encoding, regardless of the language of their content. (UTF-8 is capable of representing the full span of Unicode characters).

Your Blob likely contains one of the following:

  • Binary, non-textual data, or text in a binary-based format like old-style .doc files.
  • Text in a non-UTF-8 encoding that uses byte values above 128 in an incompatible fashion, such as Windows Codepage 1252 or something non-Western-European
  • Broken, badly-encoded UTF-8.

To solve this, you need to know exactly what your Blob contains, and if it's text, which encoding it's in. While Apex does not provide good support for text encoding conversion (it's far better to handle it outside Salesforce and always present well-formed UTF-8), nxtr has come up with a brilliant solution to hack text encoding conversion into Apex. You may be able to make use of that approach.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .