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
Rakshana Cube84Rakshana Cube84 

Apex heap size too large in VF page

Hi All

I am getting an error called "Apex heap size too large in VF page" while uploading a file via <input type="file"> component in visualforce page. I suspect it's an error from developer's side. Whenever I am uploading a file than 4MB, the error is coming.
Please help on this to get off the error. My file upload is working fine if the file size is less than 4MB
Here is my code:

<input type="file" id="fileupload1" onchange="submitImages(;"   />

 <apex:actionFunction name="submitFilename" rerender="thisform" action="{!AddAttachments}"
            <apex:param name="fileBody" value="txt"></apex:param>
            <apex:param name="filename" value="na"></apex:param>
            <apex:param name="thisCompID" value=""></apex:param>
 function submitImages(thisCompID) {
            var file = document.getElementById(thisCompID).files[0];


            if (file != undefined) {
                var attachmentName =;
                var fileReader = new FileReader();
                fileReader.onloadend = function(e) {
                    var attachment = window.btoa(this.result); //Base 64 encode the file before sending it
                    positionIndex = 0;
                    fileSize = attachment.length;
                    submitFilename(attachment, attachmentName,thisCompID);


                fileReader.onerror = function(e) {
                        "There was an error reading the file.  Please try again."
                fileReader.onabort = function(e) {
                        "There was an error reading the file.  Please try again."

                fileReader.readAsBinaryString(file); //Read the body of the file

            } else {
                alert("You must choose a file before trying to upload it");

Raj VakatiRaj Vakati
Refer this links
NagendraNagendra (Salesforce Developers) 
Hi Rakshana,

Sorry for this issue you are facing.

May I suggest you please refer to below link which might help you further with the above issue where it has a lot of useful information around heap management in this post. Hope this helps.