How to make Salesforce Apex Properties as Transient

Transient Keyword - As we always knew declaring variable as transient helps us reducing the view-state size of the Visualforce page. B...


Transient Keyword - As we always knew declaring variable as transient helps us reducing the view-state size of the Visualforce page. But what if you want to make a property as transient, Salesforce does not allow you use transient keywords with get and set method and reason being that get/set are treated as function/method in Salesforce. Clearly a method cannot be set as transient

So trying this will fail or error out

Compile Error: Methods cannot be marked transient


What is the WorkAround ?


Clearly we can declare a helper variable as transient of same type and use that variable to populate in getter and setter. Here is simply you can achieve this

This works like charm, happy coding

What Others Are Reading