I have emails attached in notes and attachments object.
When i try to read the body of Email i get Blob values suggest me ways to convert the blob into text.
You can use toString()
of Blob class.
Example:
String myString = 'StringToBlob';
Blob myBlob = Blob.valueof(myString);
System.assertEquals('StringToBlob', myBlob.toString());
Other option is by using String.valueOf()
of String class but not suggested as this returns useless string like Blob[X]
where X is the number of bytes in the blob.
There is one answer of sfdcfox which you might want to check before doing anything with blob. It says:
Blob.toString may result in an exception if the contents are not a Unicode String.
So use toString()
with Try-Catch block. Check comments too for more details.
Blob[X]
, where X is the number of bytes in the blob. For this case, I'd advise a try-catch block if the user isn't sure it's a valid string.