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
christwin123christwin123 

When to use Transient and Private Data Type

Hi,

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,
Christwin

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

http://salesforcedeveloperblog.blogspot.sg/2011/07/transient-variable-in-salesforce.html



logontokartiklogontokartik
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. 

http://www.shivasoft.in/blog/salesforce/introduction-to-view-state-in-visualforce/


Hope this helps.