You need to sign in to do that
Don't have an account?
"Static" and "Transient" variables concept with respect to VISUALFORCE Page
What is the difference between "Static" and "Transient" variables with respect to VISUALFORCE Page only.
Both are aren’t transmitted as part of the view state for a Visualforce page. Then what makes difference?
Below is the sample code I have written to understand this concept. But not understanding the exact difference.
VF Page Code
<apex:page controller="ViewStateVFCon" action="{!Method1}">
<apex:form >
<apex:pageBlock id="pb">
<apex:pageBlockTable value="{!StaticVar}" var="Tab1">
<apex:column headervalue="Record ID">
<apex:outputText value="{!Tab1.id}"/>
</apex:column>
<apex:column headervalue="Record Name">
<apex:outputText value="{!Tab1.Name}"/>
</apex:column>
</apex:pageBlockTable>
<br/><br/><br/><br/><br/><br/><br/><br/><br/>
<apex:pageBlockTable value="{!transeintVar}" var="Tab2">
<apex:column headervalue="Record ID">
<apex:outputText value="{!Tab2.id}"/>
</apex:column>
<apex:column headervalue="Record Name">
<apex:outputText value="{!Tab2.Name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:commandButton action="{!Method2}" title="Refresh" value="Refresh" reRender="pb"/>
</apex:form>
</apex:page>
VF Controller
public with sharing class ViewStateVFCon {
public static List<Account> StaticVar {get;set;}
public transient List<Account> transeintVar {get;set;}
public void Method1 (){
system.debug('Action Method1 from Page Action== ');
StaticVar = [select id, name from Account limit 20];
transeintVar = [select id, name from Account limit 20];
}
public pageReference Method2 (){
system.debug('Action Method2 from Command Button== ');
return null;
}
}
Thanks Folks..
Syed Moosa Nazir TN
smartmoosa@gmail.com
Check this link : https://developer.salesforce.com/forums/?id=906F00000008mc6IAA
Hi Anupam,
Hope you are doing great!! Thanks for sharing the link.
I have already gone through that link before posting.
In fact, when I searched in Google "static variable in view state salesforce". This was the first link appeared :) :) :)
I am not getting a clear picture (exact use case in Visualforce Page) from that link.
When to use STATIC and When to use TRANSIENT in Controller to reduce ViEW STATE.
Thanks and regards
Syed Moosa Nazir TN
Mark it solved if it answers your question.