Blob Class

Contains methods for the Blob primitive data type.

Namespace

System

Usage

For more information on Blobs, see Primitive Data Types.

Blob Methods

The following are methods for Blob.

size()

Returns the number of characters in the Blob.

Signature

public Integer size()

Return Value

Type: Integer

Example

String myString = 'StringToBlob';
Blob myBlob = Blob.valueof(myString);
Integer size = myBlob.size();

toPdf(stringToConvert)

Creates a binary object out of the given string, encoding it as a PDF file.

Signature

public static Blob toPdf(String stringToConvert)

Parameters

stringToConvert
Type: String

Return Value

Type: Blob

Example

String pdfContent = 'This is a test string';
Account a = new account(name = 'test');
insert a;
Attachment attachmentPDF = new Attachment();
attachmentPdf.parentId = a.id;
attachmentPdf.name = a.name + '.pdf';
attachmentPdf.body = blob.toPDF(pdfContent);
insert attachmentPDF;

toString()

Casts the Blob into a String.

Signature

public String toString()

Return Value

Type: String

Example

String myString = 'StringToBlob';
Blob myBlob = Blob.valueof(myString);
System.assertEquals('StringToBlob', myBlob.toString());

valueOf(stringToBlob)

Casts the specified String to a Blob.

Signature

public static Blob valueOf(String stringToBlob)

Parameters

stringToBlob
Type: String

Return Value

Type: Blob

Example

String myString = 'StringToBlob';
Blob myBlob = Blob.valueof(myString);