• Nick_Simha
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

I've run into a problem with one of my visualforce pages where I'm hitting this 128k viewstate size limit--I need some pointers on how to avoid it.

 

My page is used to display forms back to my users in a PDF. I've built the forms out in HTML tables with <apex: outputfield> components to display the data. My data structure is set up so that the user creates a Master Object, and then can create and number of child objects, which are the forms. Some of the forms have over 200 fields on them, but a requirement is that the user can display ALL forms they have filled out and print them in one page.

 

To accomplish this, I have an <apex:repeat> component on my page where the repeat variable is ALL the child records to this master object. This allows me to use the standard controller for the master object, then repeat through all the child objects and display their contents. I'm severely limited right now because once I create more than 5 forms, I start getting this viewstate error. I'm not using a custom controller, so I'm not really sure what I can do on my page to decrease this size, or handle it better. Please let me know if you have a solution!

Hi:

 

I have a visualforce page that uses the inputFile tag to up load files, code below.

I let the user upload multiple files and every file is saved using a Transient variable.


Everything seems to be working correctly, I can up load lots of files, the strange thing is when I upload a file that is 128K or more I get the "Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 130.141K" error.

 

BUT when I go to the record in sfdc the attachment is there and I can download it and view it.

 

Any ideas?

 

 

public class MyController{

private Boolean showMessage;

private Message__c newMessage;
private Attachment newAttachment;
private List<String> attachmentList;
private String attachmentName;
Transient Blob attachmentBody;

public Boolean getShowMessage(){retrun this.showMessage;}

public Message__c getNewMessage(){return this.newMessage;}
public List<String> getAttachmentList(){return this.attachmentList;}
public String getAttachmentName(){return this.attachmentName;}
public Blob getAttachmentBody(){return this.attachmentBody;}

public void setAttachmentName(String pAttachmentName){this.attachmentName = pAttachmentName;}
public void setAttachmentBody(Blob pAttachmentBody){this.attachmentBody = pAttachmentBody;}

public PageReference newMessage(){
this.newMessage = new Message__c();
return null;
}

public PageReference saveNewMessage(){
try{
insert this.newMessage;

}catch(DmlException e){
ApexPages.addMessages(e);
}
return null;
}

public PageReference saveNewMessageAndAttach(){
saveNewMessage();

showMessage = false;

return null;
}

public PageReference attachDocument(){
this.newAttachment = new Attachment();
this.newAttachment.Name = this.attachmentName;
this.newAttachment.Body = this.attachmentBody;
this.newAttachment.ParentId = this.newMessage.Id;

try{
insert this.newAttachment;
this.attachmentList.add(this.attachmentName);
}catch(DmlException e){
ApexPages.addMessages(e);

}

return null;
}

public PageReference saveMessageWithAttachments(){
this.attachmentList = new List<String>();
return null;
}

}

 

 

<apex:page controller="MyController" >
<apex:form id="messageCenter">
<apex:outputPanel id="newMsg" layout="block" >
<apex:pageBlock title="Title" rendered="{!showMessage}" >
<apex:pageBlockButtons >
<apex:commandButton value="Send" action="{!saveNewMessage}" />
<apex:commandButton value="Save and Attach" action="{!saveNewMessageAndAttach}" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="this is a test" collapsible="false" columns="1" >
<apex:inputField value="{!newMessage.To__c}" />
<apex:inputField value="{!newMessage.Name}" />
<apex:inputField value="{!newMessage.Body__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
<apex:outputPanel id="attach" layout="block" >
<apex:pageBlock title="Title" rendered="{!!showMessage}" >
<apex:pageBlockButtons >
<apex:commandButton value="Done" action="{!saveMessageWithAttachments}" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="this is a test" collapsible="false" columns="1" >
<apex:outputField value="{!newMessage.To__c}" />
<apex:outputField value="{!newMessage.Name}" />
<apex:outputField value="{!newMessage.Body__c}" />
</apex:pageBlockSection>
<apex:pageBlockSection title="Attachments" collapsible="false" columns="1" >
<apex:actionStatus id="attach" startText="Attaching..."/>
<apex:pageBlockSectionItem >
<apex:inputFile value="{!attachmentBody}" filename="{!attachmentName}" />
<apex:commandButton value="Attach" action="{!attachDocument}" status="attach" />
</apex:pageBlockSectionItem>
<apex:outputPanel layout="block" >
<apex:pageBlockTable value="{!attachmentList}" var="a" >
<apex:column value="{!a}" />
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>\
</apex:form>
</apex:page>

 

 

  • October 23, 2009
  • Like
  • 0