1

is there a way in Apex to store data in a Blob without using JSON, for example by casting? JSON has a limit when deserializing of 6MB, and our data is sometimes more than that.

The problem is that storing data as JSON within an attachment as a serialzied JOSN is possible, even if the size exceeds 6 MB, but that deserializing the same data gives the error:

String length exceeds maximum: 6000000

Is it possible to store the data - without serializing it - as a blob, and then directly casting the blob back to the data format it was originally in.

5
  • Did you try the toString() method on the blob - [blob].toString()"Casts the Blob into a String" although not sure what that would do to heap on a 6MB string
    – Eric
    Commented Jan 26, 2018 at 19:48
  • 3
    Please read x-y problem. It sounds like you've got a more fundamental problem you need solving, and this problem might not be the one you need to solve.
    – sfdcfox
    Commented Jan 26, 2018 at 19:56
  • The problem is that storing data as JSON within an attachment as a serialzied JOSN is possible, even if the size exceeds 6 MB, but that deserializing the same data gives the error "String length exceeds maximum: 6000000". So I was asking if it is possible to store the data - without serializing it - as a blob, and then directly casting the blob back to the data format it was originally in.
    – hamayoun
    Commented Jan 26, 2018 at 20:31
  • Is there a reason you don't store the data inside the json as a normal record? How are you planning to use the json data? If possible could you describe the json data you're working with a little more? (6 mb of json is quite a bit, is there binary data there?)
    – Kasper
    Commented Jan 26, 2018 at 21:11
  • 1
    @hamayoun, are you asking whether there's a way to go from Apex objects or sObjects directly to and from a binary blob, without JSON as an intermediate format? If so, the general-case answer is no, but giving more details about the problem may reveal other solutions.
    – David Reed
    Commented Jan 26, 2018 at 21:25

0

You must log in to answer this question.

Browse other questions tagged .