Activity Forums Salesforce® Discussions Which fields should we make Transient in Controller of a Visualforce Page?

  • Saurabh

    Member
    May 15, 2017 at 11:24 am

    Hi Manpreet

    Because the view state is data serialized and stored on your user’s client, it can affect your Visualforce page’s performance, and thus, your user’s experience. Not only can a large view state slow down your Visualforce page’s load time, it’s subject to a maximum view state size governor limit of 135K.

    Fortunately, you can add the transient keyword to your properties to prevent them from being included in the view state, as shown here:

    1
    transient public List<Lead> allLeadsCreatedThisYear = [Select Name, Id From Lead Limit 50000];
    Properties loaded with large collections in your controller not directly referenced by your Visualforce page are good candidates for the transient modifier. Consider whether you’ll need to recreate the property every time the page reloads, say, when a user invokes a method by clicking a button. Including the property in the view state eliminates the need for your controller to re-create it on every page load. You’ll have to decide whether it’s better for your application to have a larger view state or have more processing done on each page load.

    The Salesforce Winter ’14 Release is piloting (at the time of this writing) a new feature that allows a Visualforce page’s view state to be stored on the server rather than the client, eliminating the need to send the view state back and forth between the two. This feature resolves some of the issues raised in this section by reducing the amount of data transferred with each page request.

    The new feature is especially useful for mobile apps. These apps run on devices that are more likely to have low bandwidth or high latency. Because the view state currently gets sent back and forth between the server and client, bandwidth and latency can affect the speed of this interaction. (See Chapter 14 for more details.) When the view state is only stored on Salesforce’s server, no back-and-forth is required, freeing up bandwidth for other functions.

    Hope it may help

  • Suraj

    Member
    May 15, 2017 at 11:42 am

    Hi Manpreet,

    Declaring variables as transient reduces view state size. A common use case for the transient keyword is a field on a Visualforce page that is needed only for the duration of a page request, but should not be part of the page's view state and would use too many system resources to be recomputed many times during a request.For e.g DateTime Field can be made transient.

    For more Detail use this link.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos