Activity Forums Salesforce® Discussions What is Blob in Apex in salesforce ?

  • Nikita

    Member
    September 13, 2019 at 7:58 am

    Hi Hariom,

    Blob is a collection of binary data stored as a single object. You can convert this data type to String or from String using the toString and valueOf methods, respectively. Blobs can be accepted as Web service arguments, stored in a document (the body of a document is a Blob), or sent as attachments.

  • Saddam

    Member
    September 13, 2019 at 10:24 am

    Hi,

    A blob is data type which collection of binary data, now if i will you I world definitely want to know what is binary data, so you may aware that information in computer is stored in the form of 0 or 1, so to construct a message in particular format whether it’s image or PDF file, it will be store in the form of series of binary data and that form or collection is known as blob.

    Blob is part of System namespace which provide methods and classes for apex core functionality, so we have separate blob class, which include some functions that help us to deal with multimedia in salesforce, i.e PDF . Let see all the methods that blob class provide us,

    valueOf(stringToBlob)
    Blob is mainly use in apex to deal with creating PDF files or strings, it doesn’t used to deal with other multimedia objects like images and music, we have a function which valueOf which convert the convert/cast the string into blob object, as we are casting the string into blob the return type of it will be of blob type, see example below.

    String testString='test string';
    Blob myBlob=blob.valueOf(testString);

  • Ashutosh

    Member
    September 13, 2019 at 10:42 am

    Hi,

     

    The Blob is a collection of Binary data which is stored as object. This will be used when we want to store the attachment in salesforce into a variable. This data type converts the attachments into a single object. If the blob is to be converted into a string, then we can make use of the toString and the valueOf methods for the same

    Blob Class
    Contains methods for the Blob primitive data type
    Blob Methods
    1.size()
    Returns the number of characters in the Blob.
    2.toPdf(stringToConvert)
    Creates a binary object out of the given string, encoding it as a PDF file.
    3.toString()
    Casts the Blob into a String.
    4.valueOf(stringToBlob)
    Casts the specified String to a Blob.

  • Aditya

    Member
    November 23, 2020 at 8:31 am

    Hi Saddam,
    I want to convert a .txt file into binary string format. So, can you help me?

  • Marziya

    Member
    November 24, 2020 at 11:24 am

    Blob is a collection of binary data stored as a single object. You can convert this data type to String or from String using the toString and valueOf methods, respectively. Blobs can be accepted as Web service arguments, stored in a document (the body of a document is a Blob), or sent as attachments.

Log In to reply.

Popular Salesforce Blogs