+ Start a Discussion

When to use Transient and Private Data Type


Could someone please let me know when it would be best to use the Transient data type and the Private Data Type. I read through some documents but they are not very precise about the usage.

Thank you so Much.

Thanks and Regards,

Below blog post might help you understand about Transient keyword usage better


Hi Christwin,

private access is the least visible access modifier, any variable or method that is defined as private is visible only to that class.

transient on the other hand, is not an access modifier, but a keyword defined on instance variables. When defined as transient the variable is not saved or stored in view state. 

Generally when building huge Visualforce pages, where you have lots of variables defined in controller or lots of data loaded into lists of variable, there is a high chance of you exceeding the Visualforce page View state limitation which is 135kb.  In these cases, you need to make sure that you define the variables that are context or method sensitive as transient. 

To understand more about view state, below link has very good explanation. 


Hope this helps.