enter image description hereI have one VF page from where I am trying to download some attachments - The time I tried to download attachments which includes Attachments of size 4 MB+ size, it start showing me this error.

Exception : Apex Heap Size too large : 123454

It work fine in the Unlimited Edition.

I get that this is a Heap Size issue explained here

I want to avoid getting this error message, i.e. I want to reset or reduce my Heap Size . Please provide me some suggestions or Example using which I can get it done.

  • 1
    Can you post your code so the community can better assist you? – Berg May 2 '15 at 10:40
  • 2
    Jeff Douglas did a great post on managing the heap. Take a look at this link. blog.jeffdouglas.com/2010/08/16/… – Berg May 2 '15 at 10:43
  • To clarify, your screen shot looks like your users are selecting one or more attachments and then your code is to provide a convenient "single" zip download of them all? – Doug Ayers May 3 '15 at 17:34
  • @DougAyers : Yes, it is. – Salesforce Steps May 4 '15 at 4:42

If you want to download attachment then can you use standard view url which saleaforce provides. There you would not face heap size issue.

  • 2
    Agree. If your users are just downloading attachments one-by-one then simply provide the {!URLFOR( $Action.Attachment.View, attachment.id )} of the file and let Salesforce stream the file through the user's browser -- no heap to manage in your code. – Doug Ayers May 3 '15 at 17:35
  • 1
    @DougAyers : No I want to let them download all selected files in zip. So I can not make use of Salesforce Download URL here. – Salesforce Steps May 4 '15 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.