Skip to main content
17 votes
Accepted

How to combine multiple Blob in apex to get single Blob value

It is possible to do it by converting Blob to Hex using EncodingUtil.convertToHex() method, concat the Hex Sequence and then convert concatenated Hex string back to Blob using EncodingUtil....
Amit Jain's user avatar
  • 827
12 votes
Accepted

MD5 Blob Cannot Convert to String

Instead of toString, you need to actually use EncodingUtil.convertToHex to get the output you expect: String myString = 'Some String'; system.debug(myString); Blob myBlob = Blob.valueOf(myString); ...
sfdcfox's user avatar
  • 497k
10 votes
Accepted

How to generate a >5 MB blob for an Apex test class

You can use the string repeat method to build a long string, and then pass that to a Blob. Blob data = Blob.valueOf('a'.repeat(5242880));
Adrian Larson's user avatar
  • 151k
7 votes
Accepted

Returning a blob to a lightning component split error

You must use base-64 encoding if you want to do it this way. The reason why is that internally, Lightning uses JSON, so passing binary data through either way may have unexpected results. If necessary,...
sfdcfox's user avatar
  • 497k
7 votes

Unsupported mime Type when creating Blob instance into lightning community

We had the same problem and we opened a case: we've been told that the LockerService whitelisted the following MIME Types: application/octet-stream application/json video/ audio/ image/ font/ text/...
AlfaCold's user avatar
  • 131
6 votes
Accepted

Body not a variable of ContentVersion?

For ContentVersion, the property that contains the blob data is 'VersionData'. Line 6 should be changed to: controller.file.VersionData = Blob.valueOf('populated'); See more here: https://...
Ryan Rudd's user avatar
  • 139
5 votes

Send Blob file via Apex Rest Callout

You can't use both setBody and setBodyAsBlob in the same request. Also, if you're using multipart/form-data, you have to build a multipart payload. That means that you'll need to do something like the ...
sfdcfox's user avatar
  • 497k
5 votes
Accepted

Save base64 data as Attachment

Did you set the contentType as application/pdf? I tried this following code and it is working for me. String jsonStr = '<Base64 String>'; Attachment attach = new Attachment(); attach....
Saroj Bera's user avatar
  • 14.8k
5 votes
Accepted

What Field Type should be used to assign Blob primitive data type?

Alas, Salesforce doesn't support custom fields of the Blob type. Internally SF use Blob fields though (e.g. attachments, content files). Anyways, you have several options here. (1) Save your Blob as ...
Eduard's user avatar
  • 5,161
5 votes
Accepted

How to check Blob objects for equality?

The equals operator == does work as expected with Blob, so there's no reason to jump through extra hoops, such as your eq method. However, one possibility is that you may have had a different case in ...
sfdcfox's user avatar
  • 497k
5 votes
Accepted

How to display downloaded PDF blob in an iframe?

You have to alter your getPDF() method and prepend data:application/pdf;base64, public String getPDF() { return 'data:application/pdf;base64,'+EncodingUtil.base64Encode([SELECT VersionData ...
Pranay Jaiswal's user avatar
5 votes
Accepted

Merging Docx files into one - Apex

Aside from plain text files (e.g. source code or README.TXT type files), most files follow an internal structure. This means that two similar files (e.g. two GIF or DOCX) being "added together&...
sfdcfox's user avatar
  • 497k
5 votes
Accepted

What is the difference between Blob.valueOf and EncodeUtil.base64Decode?

tl;dr: Blob.valueOf doesn't encode or decode the string, but uses it as is, while EncodingUtil.base64Encode and EncodingUtil.base64Decode convert to/from a 7-bit safe encoding format for use in ...
sfdcfox's user avatar
  • 497k
4 votes
Accepted

visualforce to create a attachment for an object

Declare an Id variable. In the constructor, retrieve the Id of the record as follows: controller.getId(); With this Id, try to insert the attachment record. Change VFP code like this: <apex:...
Santanu Boral's user avatar
4 votes

Send Blob file via Apex Rest Callout

Proper multipart/form-data POST requests from Apex are tricky. As @sfdcfox mentioned, you need to do some very careful manipulations between the 8-bit bytes of the input file and the 6 bit groups used ...
Daniel Ballinger's user avatar
4 votes

Why does a variable of blob type, when printed gives out it's size?

Use EncodingUtil.base64Encode for the contains for the Blob. Refer EncodingUtil Class String str = 'myString'; Blob b = Blob.valueOf(str); System.debug(b); //it returns Blob[8] String base64String = ...
Santanu Boral's user avatar
4 votes
Accepted

Convert Int Array to Blob

Apex doesn't have the notion of "byte arrays", unfortunately, so there's no one-liner that can do this. The best you can do if you start from this array would be something like: Integer[] ...
sfdcfox's user avatar
  • 497k
3 votes
Accepted

Multipart form data post file with multiple form parameters?

I'd avoid manually handling the Base64 encoding yourself and the application of Grant Wickman's solution to avoid padding characters on the binary data before the multipart boundary. I looked at this ...
Daniel Ballinger's user avatar
3 votes
Accepted

Send Blob file via Apex Rest Callout

Thanks for all of your valuable feedback. Below example worked for me with some modifications. How can I compose a multipart/form-data request? Here is my code. File Upload Method public void ...
MalindaL's user avatar
3 votes
Accepted

Trying to show the content field (blob) from contentNote in Visualforce

There are two ways to convert a Blob to a string in Apex. Depending on how the Blob was created, you'll use one or the other: blobVar.toString(); encodingUtil.base64encode(blobVar); For content, ...
Matt Kaufman's user avatar
3 votes
Accepted

How do I convert a Blob into an alphanumeric string and back?

Use EncodingUtil.base64encode to convert to a String, and base64decode to get back to a Blob.
sfdcfox's user avatar
  • 497k
3 votes
Accepted

How to view attachment content?

You can get the string value of a Blob using its toString method: system.debug(a.Body.toString());
Adrian Larson's user avatar
  • 151k
3 votes

Merging pdf attachments

PDF is a binary format that, like most binary formats, simply can't be squashed together directly. It contains magic headers, object graphs, images, compression, and a bunch of other stuff that you ...
sfdcfox's user avatar
  • 497k
3 votes

MD5 Blob Cannot Convert to String

This is a useful cryptography helper class I often use: public class CryptoUtils { public static String SHA1Hash(String value) { return hash('SHA1', value); } public static ...
Robs's user avatar
  • 9,396
3 votes
Accepted

Get visualforce page pdf blob in apex

You can use any of the PageReference methods. The most straightforward would be: Blob pdfData = Page.myPageName.getContent(); Note that this technically still counts as a callout (meaning, you ...
sfdcfox's user avatar
  • 497k
3 votes
Accepted

Formatting Excel Column from Apex

This is an locale + Excel issue. You cannot apply formatting in a CSV file as such. You're outputting dates in DD/MM/YY format. Excel is reading them in MM/DD/YY. If you notice which dates are and ...
David Reed's user avatar
  • 93.2k
3 votes

Why Blob equals doesn't work if one of the Blobs is retrieved from ContentDocument?

As guessed in the comments, .equals() behaves as the === (exact equality operator), which generally checks to see if two objects are the exact same object in memory. Instead, you'd want to use == ...
sfdcfox's user avatar
  • 497k
3 votes
Accepted

How to read/parse an X9.37 file via Apex?

Your example file is apparently in "EBCDIC" encoding. Apex only supports UTF-8, which EBCDIC is definitely not compatible with; EBCDIC is an IBM mainframe spec that is mostly a holdover from the days ...
sfdcfox's user avatar
  • 497k
3 votes
Accepted

Weird "common.apex.runtime.impl.ExecutionException: Syntax error"|0x78b85a0a while doing a Callout

I was able to figure it out. As the hint of the last character was giving it turns out that I had checked by mistake the Allow Formulas in HTTP Body in the Named Credentials definition. So because I ...
ymiki's user avatar
  • 73
3 votes
Accepted

How can I insert an image blob obtained from the ClipboardAPI as a file attached to a record, via an LWC?

To fix your issue with attaching images in Salesforce using LWC, you'll need to tweak how the image data is handled. Start by converting the image (which you got from the ClipboardAPI) into a base64 ...
aryashah2k's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible