3

I need to assign Blob value to a field. I've already tried Text and URL field types but I've got next error Illegal assignment from Blob to String. Is it possible? What field type should I choose?

Thanks for any help, Vlad

2
  • Ultimately, this may be an X-Y problem. What's your intended purpose?
    – sfdcfox
    Commented Jul 30, 2018 at 7:55
  • @sfdcfox I'm creating class externally using javascript and inserting it. And I need to create assert test method for this class. I've already made it for other types such as Number, String, etc. and now it's time for Blob. Commented Jul 30, 2018 at 8:27

1 Answer 1

5

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 an attachment (or a content file) and relate it to a record. (2) Use a text area (long) custom field and store your blob as base64 encoded text. In this case you should consider the size of the resulting text string which should not exceed 131,072 characters.

There is an idea out there you can vote up.

3
  • the second option isn't helpful in my situation. I need blob type and not a string. I've tried to create Attachment object and add my blob value to a Body field but it's also requires ParentId value Commented Jul 30, 2018 at 8:33
  • 3
    The ParentId is the Id of the record you are trying to create. So in your test do it in two steps. 1. Create the record, insert. 2. Create the attachment with the Blob and set the ParentId. Commented Jul 30, 2018 at 8:49
  • 1
    First option helped for me, thanks. I've made new attachment object, with Name, Body (Blob value) and ParentId (account ID value) fields. And inserted it. Commented Jul 30, 2018 at 8:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .