Activity Forums Salesforce® Discussions What Is Visualforce View State? And What Are Best Practices To Reduce The View State Size?

  • What Is Visualforce View State? And What Are Best Practices To Reduce The View State Size?

    Posted by Aman on September 20, 2018 at 3:11 pm

    What Is Visualforce View State? And What Are Best Practices To Reduce The View State Size?

    Parul replied 5 years, 7 months ago 3 Members · 2 Replies
  • 2 Replies
  • shariq

    Member
    September 20, 2018 at 3:14 pm

    Hi,

    Visualforce pages that contain a form component also contain an encrypted, hidden form field that encapsulates the view state of the page. This view state is automatically created, and as its name suggests, it holds the state of the page – state that includes the components, field values and controller state.

    Best Practices to reduce the view state size:

    Minimize number of form on a page.  Use apex:actionRegion instead of using 2 or more forms.
    Refine your SOQL to only retrieve the data needed by the page.
    All public and private data members present in Standard, Custom and Controller extensions are saved.
    Mark any Apex variables that are not necessary to the view state as Transient. (The transient variables are not passed to view state and therefore not stored in View State)
    Create wizards with as few pages as possible
    Use outputLink components instead of commandLink or commandButton components where possible as they don’t need to be nested in a form.

    Thanks

  • Parul

    Member
    September 20, 2018 at 4:12 pm

    Adding some points:

    Visualforce pages that contain a form component also contain an encrypted, hidden form field that encapsulates the view state of the page. This view state is automatically created, and as its name suggests, it holds the state of the page – state that includes the components, field values and controller state.
    Note:
    Minimize number of form on a page.  Use apex:actionRegion instead of using 2 or more forms.
    Refine your SOQL to only retrieve the data needed by the page.
    All public and private data members present in Standard, Custom and Controller extensions are saved.
    The transient variables are not passed to view state and therefore not stored in View State.

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos