0

I created a page that passes a file from the VF to the Controller. It's working fine, except when the file is bigger I hit the blob limit in the controller.

What I do:

  1. On the front end I convert the attached file to a string.
  2. Pass that string to a variable in the controller.
  3. Then do blob.valueOf() to convert the string to a blob. Then I assign that blob to the attachment.Body.

I was following this article: http://manojjena20.blogspot.com/2015/11/apexinputfile-can-not-be-used-in.html

Now my issue is when I try to attach a bigger file. I get this kind of error: String length exceeds maximum: 6000000 on the line that convers the string to a blob.

What can I do to assure that bigger files can be converted and uploaded as well?

2

You have few options here:

1 - Ask Salesforce to increase the file limit in your organization (they can set it up to 25mb according to Jeff Douglas).

2 - Rework your code to use the Ajax Toolkit (JavaScript) to upload the file, so you can upload larger files. This answer can clarify that, I believe.

3 - Use a third-party application connected to Salesforce to receive the files, as in this answer.

6
  • Thank you. Now I experience an issue on the front end too getting a Maximum view state size limit (135KB) exceeded. How is that possible? – Arthlete May 24 '16 at 0:27
  • 1
    When you save the file, are you setting the file's variable to null? You must do so when your attachment exceeds the view state's size. For example: it is ok if you upload a 200kb file. But if you don't set the variable - to which the file was bound - to null when the page is rerendered, then Salesforce will try to cache the file in the view state (and it will exceed the limit). – Renato Oliveira May 24 '16 at 0:39
  • Do you mean the variable in the controller? – Arthlete May 24 '16 at 16:57
  • 1
    Yes, the variable you use to assign the file. – Renato Oliveira May 24 '16 at 17:00
  • 1
    I think you can solve that by using an internal list that won't be accessible in the controller (see how to use the Transient keyword developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…). Using this you can store the attachments in this variable (that won't be loaded in the view state) and have a different list with a custom wrapper class to hold the attachments' information (like name, size, but not the body) and then show this instead of the list of attachments. – Renato Oliveira May 24 '16 at 17:23

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.