function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ankita Gupta 65Ankita Gupta 65 

apex heap size too large error in APEX REST

Hi All,
I have created an APEX REST service to insert few records in custom object and few attachments. The service works fine for multiple attachments of size ~60KB. However, when attachments of size ~2MB is sent, we get an error 'Apex heap size too large'. I have a requirement where multiple attachments of size ~3MB should be inserted using REST API. Please help.
Cloud AtlasCloud Atlas
I am sure you must be aware of Heap Size limit of 6 MB for Synchronous and 12 MB for Asynchronous ..
So can you modify your code to only ask 1 attachment at a time.
The attachment could be either 60 KB or 3 MB.
In this way you will never hit Heap Memory limit...

If for some reason , you cannot modify your code to limit the transaction to 1 attachment, ask the sender ( developer of the other system with which SFDC is integrating) to send only 1 attachment per request from SFDC.
This is the only solution I can think of at this time.
 
Ankita Gupta 65Ankita Gupta 65
@Cloud Atlas
Thanks for your response. Can you help me understand how can I limit it to 1 attachment since I'm at the end where we are writing the service. Since we are getting 1 json that includes all the records for different objects and attachments
Sanjay Patidar 29Sanjay Patidar 29
@Ankita - We have a similar requirement. Can you kindly share sample code and also how you created the JSON structure for this requirement.