String str = 'myString';
Blob b = Blob.valueOf(str);

Here if I print str then the value of str(I believe it is usingvalueOf()method explicitly) is printed but when I print b then the it returns the size, why? If I want to know the value of blob(binary data for the same) then how can I extract that?

  • The reason why is because the Debug Logs are a UTF-8 stream, and outputting arbitrary data could make the file invalid. – sfdcfox May 14 '18 at 12:40

Use EncodingUtil.base64Encode for the contains for the Blob. Refer EncodingUtil Class

String str = 'myString';
Blob b = Blob.valueOf(str);
System.debug(b); //it returns Blob[8]
String base64String = EncodingUtil.base64Encode(b);

System.debug('encoded string=' + base64String); //it returns bXlTdHJpbmc=

System.debug('decoded string=' + EncodingUtil.base64Decode(base64String).toString()); //it returns myString
| improve this answer | |
  • //it returns Blob[8], no it returns 8. System.debug(b) returns Blob[8]. – sfdcfox May 14 '18 at 12:41

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.