Activity Forums Salesforce® Discussions How to combine the blob value of multiple blob in Salesforce Apex Code?

  • Himanshu

    Member
    August 5, 2016 at 7:03 am

    Hi Mohit,

    Blob bb1 = Blob.valueOf(‘s1’);
    Blob bb2 = Blob.valueOf(‘s2’);
    Blob bb3 = Blob.valueOf(‘s3’);
    
    String combinedDataAsHex = EncodingUtil.convertToHex(bb1) + EncodingUtil.convertToHex(bb2) + EncodingUtil.convertToHex(bb3);
    Blob combinedDataAsBlob = EncodingUtil.convertFromHex(combinedDataAsHex);
  • Avnish Yadav

    Member
    September 30, 2018 at 4:08 am

    Hello,

    Blob is a sequence of Bytes and it need to be converted to string representation for concatenation. In Apex there are only two ways to convert Blob to String, either use base64Encode or convertToHex as suggested above. base64Encode will not work in this case as base64Encode appends additional information during encoding and this causes corrupted data if two base64Encoded Blob values are combined and converted back to Blob using EncodingUtil.base64Decode() method.

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos