[SalesForce] Heap Size Limit: Can we split up Blobs

Whilst parsing text files using Batch Apex, we retrieved an Heap Size error. The Heap Size limit happens before our custom Iterator. Because we parse an attachment, change it into a Blob and then retrieve 1 large String value. This transformation from Blob to String is providing the issue. The Blob itself has a very small Heap size but when we transform it to a String, the heap size easily quadruples. Is there a way to create an Iterator on a Blob object? I'm assuming that this is not possible since we cannot use any 'split' functions on a Blob file.

Any ideas?

Best Answer

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 single conversion blows the heap-size limit, there is not much you can do programmatically.

You could try one feature what I remember but never used called "Future Methods with Higher Limits (Pilot)".

It allows you to do stuff like

@future(limits='2xHeap')
public static void myFutureMethod() {
    // Your code here
}

With that feature you might be able to move the conversion into a future call. But without deep look into you code, I can't tell if it's really possible in your situation.

The feature seems to be still in pilot. If that is true, you need to apply (via support, you AE or evangelist) to get it activated. Not guaranteed that you get it.

Related Topic