I am currently working on an integration project involving the Salesforce API. My project uses an Apex class to call a Quarkus service that interacts with a Document Management System (DMS) on Azure. This class is designed to retrieve a list of documents from the DMS.

However, I am running into an issue when the size of a document exceeds the total heap size limit imposed by Salesforce. Specifically, Salesforce has a 6 MB limit for synchronous transactions and a 12 MB limit for asynchronous transactions. When I try to retrieve a document that exceeds these limits, I am unable to do so.

I was wondering if anyone else has encountered this issue and if so, how did you resolve it? Any help or suggestions would be greatly appreciated.

  • I would see if you can have Quarkus call SFDC to fetch the document
    – cropredy
    Commented Jul 31, 2023 at 21:28

1 Answer 1


You would need to get the documents as Chunks (if the size is more than 6MB then split it into more documents) and store it in SF. You can also try other options to get a direct upload instead of using DMS to Integrate with SF.

Try to get OmniOut option if your project have Omnistudio which allows upto 30 MB of document that can be transferred to SF (this uses REST API behind the screen to upload to SF) Or you can use REST API document transfer which allows upto 2GB of document that can be transferred to Salesforce.

Try to get the limits exceeded or not with a variable called allowedHeapSize, you can set the value for this and then do a check like this,

Considering that your total file size is 30 MB and you want only 5 MB to be extracted for your first chunk, you can set allowedHeapSize as 5 MB and do a check for limits exceeded or not is lesser or equal and then create.

if((Limits.getLimitHeapSize() - Limits.getHeapSize()) <= allowedHeapSize)
// allow file creation

Do a read on the first chunk and get the last line's index and keep this index search as your delimiter for the next chunk file to be created in SF.

You must log in to answer this question.

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