0

I would like to see the Attachment body in plain string, but cannot find out how.

For ex:

Attachment a = [SELECT Id, Name, Body, ContentType, ParentId FROM Attachment WHERE ParentId = 'a016A000000agQ6QAI'][0];
System.debug(String.valueOf(a.Body));

The output is:

12:28:14:022 USER_DEBUG [2]|DEBUG|Blob[472]

But I need to see in a String the actual content of the attachment body. How can I do it?

1

2 Answers 2

3

You can get the string value of a Blob using its toString method:

system.debug(a.Body.toString());
1
  • Works like charm, tried String.valueOf before your reply and didnt worked.
    – BoDiE2003
    Jun 7, 2017 at 17:59
1

Convert Blob to String:

System.debug(EncodingUtil.base64Encode(a.Body));

You must log in to answer this question.

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