1
String str = 'myString';
Blob b = Blob.valueOf(str);
System.debug(b);
System.debug(b.size());
System.debug(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?

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

1 Answer 1

4

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
1
  • //it returns Blob[8], no it returns 8. System.debug(b) returns Blob[8].
    – sfdcfox
    Commented May 14, 2018 at 12:41

You must log in to answer this question.

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