+ Start a Discussion
alex51atlaswalex51atlasw 

Redirect fails when using transient keyword

I've create a visualforce page which contains all the counts of data associated to a particular user (i.e. num prospects, num opportunities, num tasks, etc), when a user clicked on any of the numbers they would be redirected to a detail page containing a list of all those particular objects. Once in production we ran into "Maximum view state size limit (128K) exceeded" issue. To fix this I added the transient keyword to each of these variable lists which contain the count. However, when the user clicked on any link containing the object count, the page would no longer be redirected to the appropriate page but rather just refresh the current one. Upon clicking the count links I query for the objects again so its not an issue with the variables not in the view state, it just seems to be an issue with having the transient keyword and not allowing me to redirect. Any ideas as to why this is happening?

 

I can provide code if needed. Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
hgarghgarg

I think the basic behaviour of transient variable is only during the request.

For example:-

1) if you set the value of a transient variable and display it on the visualforce page.

2) Now suppose you have a commandButton or by any means you come back to your controller and try to access that transient variable, then you will find that the transient variable vanishes, you will not get the value that you have set in first step.

Hoe it helps you.

 

 

All Answers

forecast_is_cloudyforecast_is_cloudy

Can you please provide the code in question? Thanks.

hgarghgarg

I think the basic behaviour of transient variable is only during the request.

For example:-

1) if you set the value of a transient variable and display it on the visualforce page.

2) Now suppose you have a commandButton or by any means you come back to your controller and try to access that transient variable, then you will find that the transient variable vanishes, you will not get the value that you have set in first step.

Hoe it helps you.

 

 

This was selected as the best answer
alex51atlaswalex51atlasw

Thank you for your replies, I eventually went another route where I did not run into this issue. The way it was being coded was error prone and I eventually redesigned it. Thanks again.

Ani2324Ani2324

Hi,

 

Iam also facing the same issue. Can you plz tell me the solution for this.If possible post the code.Thanks in advance.

 

Regards,

Anil

sapthagiri_186sapthagiri_186

Hey,

 

I am having the same issue and by using "Transient", my problem didn't work out. I have a requirement where user have to enter an activity and can also attach a file if there is one. In order to do so, he enters all the activity details and clicks on "Upload a File" button, which redirects to a new page where he could attach a file. Here he selects a file and clicks on "Upload" (where it only gets uploaded but not saved) which again takes back to the previous page where he'd entered the activity details. Here upon clicking "Save" button, the activity entered and the file attached gets saved and inserted respectively to that particular activity "Notes and Attachment" section.

 

I have used ""Transient" like public transient Attachment document{get;set;} but it didn't help me. If i remove "Transient" and try uploading, it did work out for files with lesser in size, but I get an error message (Maximum view state size limit (135KB) exceeded.) for view state if the size exceeds 135kb. 

 

Best Regards

digamber.prasaddigamber.prasad

Hey,

 

If you set body of attachment after inserting it to null, you will not get View State issue. It should be something like:-

 

.

.

.

insert document;

document.body = null;

.

.

.

 

Hope this will help you.

 

Cheers!