function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hemmhemm 

Viewstate and Getter methods

I am working through some ViewState issues and I have a question.  I use the following paradigm regularly in my development and want to know how I am contributing to the ViewState.

 

I often keep data in the controller in a private list of a custom wrapper class.

 

private list<myClass> allMyClass = new list<myClass>();

 

I will often have several "get-only" properties that pull back subsets of list data.

 

public list<string> subset1MyClass	{
	get{
		list<string> tmpList = new list<string>();
		for (myClass m : allMyClass){
			if (m.property1 == true){
				tmpList.add(m);
			}
		}
		return tmpList;
		}
	} 
public list<string> subset2MyClass	{
	get{
		list<string> tmpList = new list<string>();
		for (myClass m : allMyClass){
			if (m.property2 == true){
				tmpList.add(m);
			}
		}
		return tmpList;
		}
	} 

 

 

It is these get-only properties that I use to make pageBlockTables and the like.  They are the public facing lists from my controller.

 

Since subset1MyClass and subset2MyClass are Getter methods, I cannot make them transient.

 

What I want to know is whether subset1MyClass and subset2MyClass contribute to View State.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I'd say that you want to create a lightweight custom class that represents some aspects of an attachment (such as the name and id).  Pass this information back and forth between the page, then when you need to send the email retrieve the genuine attachments.

 

 

All Answers

bob_buzzardbob_buzzard

The docs don't give a direct answer to this question, but it seems unlikely if that's any help :)

 

According to the docs, the viewstate is used to update the values on the page.  As you only have a getter, you won't be able to back input fields with these lists, so they won't be used to keep the state of the page.

 

Plus you are creating the results on the fly, so there is nowhere for this data to be applied from the view state, and I'd expect an error if it was trying to update the results on a post.

 

 

hemmhemm

Thanks for the response.  I am working through some View State issues and am trying to rule out categories of things that could be contributing to it.  I have assumed (and hope) that, because those properties are get-only, that they are considered methods and not part of the View State.

 

I wanted to get a definitive answer from the VF team about this.  I could imagine there being an issue where the system sees those as properties (instead of only as methods) and hangs onto them in the View State.  If that is the case, then I will re-architect those properties to be more traditional methods in the hopes that it helps.

 

View State is a bit of a mystery and I am looking for someone from salesforce to confirm specifically what things are in the View State and what are not.  Even better would be some thing we could do (perhaps a Sites page they run for us) that deconstructs the View State for us so we can get a picture of what's inside and what's taking up the space.  Something like that would help in the hunt for trimming the pages down.

stephanstephan

Hey guys --

 

Yes, the docs on view state are a little sparse. They'll be expanded in the Summer '10 release, in conjuction with a beta/pilot feature you might find useful -- an additional tab in developer mode that allows you to see exactly what's in view state.

 

To answer your question about what's in view state, here are the contributors:

 

1) Non-transient fields in your controller, extensions, and component controllers. Whether or not you have a getter, or what that getter returns, doesn't affect view state size.

2) The component tree for the page as well as that of any custom components.

3) Visualforce internal overhead.

 

Again, we'll have more on the subject in the Summer '10 Visualforce Developer Guide. Also let me know (feel free to email me at smorais@salesforce.com) if you'd like to be a part of the initial pilot for View State Inspector feature.

 

...stephan

 

hemmhemm

Thanks!

 

Just to confirm... In the example I posted in the initial part of this thread:

 

  • allMyClass would be part of View State
  • subset1MyClass would not be part of View State
  • subset2MyClass would not be part of View State

Correct?

stephanstephan

Correct.

newVFdevnewVFdev

I am struggling with the wrapper class for attachments and theviewstate!

I have the following situation:

When a user save an event, he can add attachments wich display in the relatedList. After a user saved the Event he can send a report on event. Nowe when the event view page, he can click on a custom Button calls  "send Report"

this link calls a visualforce page which include the name of invited attendees and the attached files to the report. The user can then select the attachment he needs to send in that report and  the report will be sent with the selected attachments to the selected attendees!

Actually this works very good when the files are small, but If I have a file which is bigger than  240Kb, I get the viewstate error.

I have read the documentation on the viewstate and  none of the method suggested helped, when I use transient, I cann see the attachmentList and select then no attachment was sent. Now the other suggestion was to use custom object to store the attchment inside, but then there is no example how to do that. I may have missed something and I am quite new to visualforce. Also I tried to set body to null but I get the following error when I select attachments to be sent:

SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, No body specified in the file attachment

 

any help would be much appreciated!

Thanks.

bob_buzzardbob_buzzard

I'd say that you want to create a lightweight custom class that represents some aspects of an attachment (such as the name and id).  Pass this information back and forth between the page, then when you need to send the email retrieve the genuine attachments.

 

 

This was selected as the best answer
newVFdevnewVFdev

Thank you very much! You are my champion :-)

That resolved my issue I have been struggling with this for days. And your answer helped me to resolve that in one minutes!!!

newVFdevnewVFdev

How can I mark a post as a solution? I am quite new to the community and don't know how to--