2

Good day Everyone,

I am trying to upload a csv file. I don't have any issue when trying to upload a small csv file. But the problem is that, when I try to upload a large file I get an error in "Maximum view state size limit (135KB) exceeded". So I used "transient" keyword for my variable.The process is that I upload the csv file, go to different pages and then get the variable. But my problem is that when I used transient the data will be null. What is the best thing to do to solve my problem ?Is there any way not to used "transient" and avoid the error ? or I have to used transient coz there will be a way to get the data ? Pls help.

Thank you.

  • which variable you get, what does it contains? – Ashwani Aug 17 '15 at 10:56
  • @Ashwani the transient variable that contain my very large data basically i'm using a blob datatype. – Hope Aug 17 '15 at 10:58
3

I faced an issue on the same grounds, I wont say its 100% same but it might give you some clue.

    public void Upload(){
       try {
          attch.Name = nameFile;
          attch.ParentId = csvHeader.Id;
          insert attch;
       } catch (DMLException e) {
           ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error'));
       } finally {
            attch.body = null; // clears the viewstate
            attch= new Attachment();
       }
  }

Basically all that I did was made the body as Null right after the attachment was inserted. If this doesnt help you. You can do a hack like create a temporary folder in Documents and each time you upload, insert the file there and query it from there when you navigate through pages!

| improve this answer | |
1

After uploading you file you need to set that blob variable to new blob object instance.

Thanks,

| improve this answer | |
  • I am quite confuse can you give some code . thanks – Hope Aug 18 '15 at 1:24
  • I try this one but it seems it doesn't fix the issue. Can you please show me a sample code ? – Hope Aug 18 '15 at 2:06
0

You can try private variable, assign value to private variable in controller and then get value in second page or second approach is first insert csv as attachment and keep the id and in another page query this attachment in local variable. It also doesn't affect your viewstate. Every public variable with {get;set;} are counted in ViewState. Also set attachemnt att = new attachemnt();

In this way you can clear previous value and minimize yoyr view state. Also you can take help from here or here.

| improve this answer | |
  • I try to use private variable but it seems it cannot be seen in my visual force page. An error occured "Unknown:method". Can you please show me a sample code ? Thanks. – Hope Aug 18 '15 at 2:05
  • No this private variable is only for your controller use. get value from page in public variable and then keep copy of data in private variable. – Tushar Sharma Aug 18 '15 at 4:57
  • Actually I also tried to use 2 variable one private and one public after I Use the public to for the visual force page. And then after that I pass the data from public to private but the "Maximum view state" error occured. – Hope Aug 18 '15 at 5:19
  • @Hope try to make public variable transient if it don't affect your functionality and keep value in private variable for future reference. – Tushar Sharma Aug 18 '15 at 11:49
0

Use one apex:form not more than one. If you want to use more apex:form then user the apex:actionRegion or apex:outputPanel which reduces he view state of page.

Thanks, Prakash

| improve this answer | |

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.