Newer Version Available
Blob Class
Namespace
Usage
Salesforce supports Blob manipulation only with Apex class methods that are supplied by Salesforce. For more information on Blobs, see Primitive Data Types.
Blob Methods
The following are methods for Blob.
size()
Signature
public Integer size()
Return Value
Type: Integer
Example
1String myString = 'StringToBlob';
2Blob myBlob = Blob.valueof(myString);
3Integer size = myBlob.size();toPdf(stringToConvert)
Signature
public static Blob toPdf(String stringToConvert)
Parameters
- stringToConvert
- Type: String
Return Value
Type: Blob
Usage
Blob.toPDF(stringToConvert) doesn't support web fonts, so you can't specify a font for the string.
Blob.toPDF(stringToConvert) also doesn't support multibyte characters, such as Japanese and accented international characters. To render multibyte characters in a PDF file, consider adding the string to a Visualforce page, and then rendering the page as a PDF file. See Render a Visualforce Page as a PDF File.
Example
1String pdfContent = 'This is a test string';
2Account a = new account(name = 'test');
3insert a;
4Attachment attachmentPDF = new Attachment();
5attachmentPdf.parentId = a.id;
6attachmentPdf.name = a.name + '.pdf';
7attachmentPdf.body = Blob.toPDF(pdfContent);
8insert attachmentPDF;toString()
Signature
public String toString()
Return Value
Type: String
Example
1String myString = 'StringToBlob';
2Blob myBlob = Blob.valueof(myString);
3System.assertEquals('StringToBlob', myBlob.toString());