0

I have a visualforce page which has control. I am using this to upload a text file. I have property of type Attachment in my controller. Value of inpufile control will be Body of Attachment property.

In my controller action method, I am reading file contents as -

string attachmentBodyString = attachmentProperty.Body.toString();

I need to parse this string to do some business logic. For larger files, I am running into Heap size limit error.

text file is around 1.5MB in size with around 15K lines.

I tried doing optimization wherever I can but still running into issues.

Can someone suggest any workaround for this ?

  • and the heap size error occurs whilst parsing the lines? Like on line xxx? – cropredy Jan 31 '15 at 1:18
  • 1.5MB is well below the heap size limit (6MB). Are you talking about the view state limit of 135KB? If you're hitting the heap limit, there's still some optimalization to be done. If you're hitting the view state limit, try to remove the attachment from the view state of the page (by making the variable transient). In that case you will have to query for it every time you need it though. – rael_kid Jan 31 '15 at 11:53
  • @Lex , I am running into heap size limit and not view state limit. I read the attachment as string in apex code and I believe this is where the error occurs. – apn Jan 31 '15 at 14:57
  • Still, that would mean 1.5MB for the attachment, and another 1.5MB for the string. Can you share the entire code? – rael_kid Jan 31 '15 at 15:29
0

finally i optimized the code wherever i can. Got rid of temporary string variables and was able to make the code work for file size of 1.5 MB. It is now optimized to the point where it should be able to handle upto 3 to 4 MB file.

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.