Best Practices for View State

View state has a limit of 135k

Best Practices to optimize your view state

  • Minimize number of forms:
    Avoid using multiple form tag in VF page
    Instead of using multiple forms use <apex:actionregion> to submit portions of the form.
  • Declare variables as Transient.
    if you have referred section view state in VF page you must be aware that non-transient variables are stored.
    If variable is declared as Transient it is not saved and is not transmitted
  • Recreate state instead of storing
    if you can recreate the data during postback using SOQL , you must do that
  • Use Custom settings or Custom objects to store the read only data
  • Only Add the fields in SOQL which is required