Hot answers tagged

16 votes

Post multipart without Base64 Encoding the body

Fix for occasional corruption when uploading a file from Salesforce using multipart mime. The Salesforce solutions for multipart mime so far have left one problem outstanding, in that very ...
user avatar
16 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....
user avatar
  • 745
13 votes
Accepted

Why is String.valueOf(Blob) different that Blob.toString()?

String.valueOf returns Blob[X] for Blob values. I believe it does it this way because System.debug internally uses String.valueOf, and debugging a potentially non-Unicode stream into a Unicode String ...
user avatar
  • 430k
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); ...
user avatar
  • 430k
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));
user avatar
  • 142k
8 votes
Accepted

Save attachment with Remote Objects

Based on the error message you get when you attempt to retrieve the body of an attachment: Visualforce Remoting Exception: No serializer found for class common.udd.object.EncryptableFfxBlobField$...
user avatar
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,...
user avatar
  • 430k
6 votes
Accepted

dataURL to blob

You need to specify the file extension when giving name to the attachment. a.Name = 'attachment.png'; Or alternatively set the ContentType attribute - Attachment Object Update: Your string is ...
user avatar
6 votes

How to use Blob inside a Trigger (BLOB is not a valid UTF-8 string)?

You have somehow embed the binary data into the field. Here's one way: trigger Update_image on FeedItem (after insert) { id Travelid ; blob img; // Just binary data, thanks! List<...
user avatar
  • 430k
5 votes
Accepted

Combine multiple PDF's together and attach them in a mail?

There's no way to combine PDFs as such. What you would need to do is generate your PDF in a different way, i.e. from a List as opposed to the single record. You can utilise the visualforce that you ...
user avatar
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....
user avatar
  • 12.7k
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 ...
user avatar
  • 430k
5 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://...
user avatar
  • 129
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 ...
user avatar
  • 4,645
5 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/...
user avatar
  • 111
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 ...
user avatar
  • 430k
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&...
user avatar
  • 430k
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:...
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 ...
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 = ...
user avatar
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 ...
user avatar
  • 430k
3 votes
Accepted

List out of bound exception at List<Blob>

Instead counter use b.size() for(integer i = 0; i <b.size(); i++) { Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName('attachment.pdf'); efa.setBody(...
user avatar
3 votes

Alternative to renderas PDF for converting an HTML to PDF in apex

There are a number of AppExchange packages that can generate a PDF using a template- Conga, Drawloop, and Thunderhead are three well known ones. Generally these templates are built in Word or another ...
user avatar
3 votes
Accepted

Getting Blob data from content document using File Sync

The trigger can also be written on COntent Version .The content version object has field version Data and that holds data in base 64 encoded format . https://www.salesforce.com/developer/docs/api/...
user avatar
3 votes

Heap Size Limit: Can we split up Blobs?

If the limit would be blown by a repetitive conversion, it's important to make sure that big string falls out of scope before the next iteration to prevent a growing heap consumption. If even a ...
user avatar
  • 33.5k
3 votes

Select body Of attachments

I know this is four months old, but I just ran into this myself, and may have a reason as to why this occurs. There is a very small blurb at the bottom of this page on the developers site : You can ...
user avatar
  • 131
3 votes

Reading a pdf file in apex controller

If you mean you want to look at the bytes that make up the file using Apex code you can't directly. You can turn it into a base64 string using EncodingUtil.base64Encode but as the string characters ...
user avatar
  • 129k
3 votes

Blob store the data in binary form or in base64

File upload between a browser and a HTTP server encodes the data using "multipart/form-data" encoding (see e.g. http://www.rfc-editor.org/rfc/rfc1867.txt) and this allows the form fields and the file ...
user avatar
  • 129k
3 votes
Accepted

Send email with excel attachment - Blob variable doesnot exist error

The Blob.valueof method requires a string to be passed into the object. You will first need to convert the Map to the string representation of the of the CSV data. I had ran into that issue once ...
user avatar
  • 743
3 votes

How to concatenate two PDF in Apex

If you have more than one PDF, you'll need to send them as separate attachments. You can't just append one PDF to the next without "re-rendering" each page, then compiling a new PDF from within ...
user avatar
  • 40.3k

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