
How to reduce View State:
- Use the transient keyword: The simplest and the most logical way is to keep the size of the VF page as small as possible. ...
- Refine your SOQL: Reduce the number of records displayed on a page by refining SOQL. ...
- Minimize the Number of Forms on a Page: We should use <apex:actionReagion> instead of using two <apex:forms>. ...
- Use Custom Setting: Use custom setting to store large quantities of read-only data instead of custom objects. ...
- Use <apex:outputLink> : Instead of using <apex:commandLink> or <apex:commandButton> components, Use <apex:outputLink> because <apex:commandLink> or <apex:commandButton> requires to be included inside a <apex:form> component unlike <apex:outputLink>.
- "Transient" keyword - to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a VF page. ...
- Minimize the number of forms i.e <apex:form> on a page. ...
- Refine your SOQL to retrieve only the data needed.
How to optimize the view state size in Salesforce?
This information can help you in optimizing the view state size. Once enabled, it shows up as a tab in Development Mode, as follows. you can enable that from Edit User-> Select view state checkbox after development mode checkbox.
How can I improve my view state in Visualforce?
If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page. If your view state is affected by a large component tree, try reducing the number of components your page depends on.
What is view state in Salesforce soql?
If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page. View state holds the state of Visual force page.
Why are my view state values private in Salesforce?
define private if they are not used on visualforce page. If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page.

How do you reduce viewstate?
Assuming you currently are using viewstate ONLY where you need you can do the following:Switch Labels to Literals , especially if you are using them in templates. Labels take much more viewstate.Try do reduce postbacks. ... Use session or caching to store large amounts of data for grids and data heavy controls.
What is viewstate in salesforce?
View state holds the state of Visual force page. The view state of a web page is composed of all the data that's necessary to maintain the state of the controller during server requests (like sending or receiving data).
How do I fix maximum view state size limit 170kb exceeded?
In order to avoid this error, minimize your pages' view state. You can optimize your Apex controller code and remove any superfluous Visualforce components used.
How do I view viewstate in salesforce?
View State TabFrom your personal settings, enter Advanced User Details in the Quick Find box, then select Advanced User Details. No results? ... Click Edit.Select the Development Mode checkbox if it isn't selected.Select the Show View State in Development Mode checkbox.Click Save.
What is the difference between Actionsupport and actionFunction?
Action function can call the controller method from java script. 2. Action support adds AJAX support to another visualforce component and then call the controller method. Here action support adds AJAX to output panel, so once you click on output panel controller method will be called.
What is the difference between action function and @remote action?
In general, apex:actionFunction is easier to use and requires less code, while @RemoteAction offers more flexibility. Moreover, @RemoteAction helps in reducing View State size and also provides you near real time transaction.
What is the maximum size of a Visualforce page?
Visualforce LimitsLimitValueMaximum view state size in a Visualforce page170KBMaximum size of a Visualforce email template1 MBMaximum file size for a file uploaded using a Visualforce page10 MBMaximum size of HTML response before rendering, when Visualforce page is rendered as PDFLess than 15 MB16 more rows
How do I use transient keyword in Salesforce?
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.
What is view state error in visualforce?
If the size of a particular page exceeds 135kb, the page will throw a view state error. A screenshot showing a view state error in salesforce. To check the view state of a visual force page you have to make sure that Show View State in Development Mode checkbox in the User Layout is checked.
What is heap size limit in Salesforce?
Salesforce enforces an Apex Heap Size Limit of 6MB for synchronous transactions and 12MB for asynchronous transactions. The "Apex heap size too large" error occurs when too much data is being stored in memory during processing.
How do I know my view state size?
To monitor view state, you must first enable this by going to My Settings | Personal | Advanced User Details and clicking Edit. Select the Development Mode AND Show View State in Development Mode checkboxes and click Save.
What is SOSL in Salesforce?
Salesforce Object Search Language (SOSL) is a Salesforce search language that is used to perform text searches in records. Use SOSL to search fields across multiple standard and custom object records in Salesforce. SOSL is similar to Apache Lucene.
Controller Data - Use transient
To reduce the amount of data needed to store the state of your controller you can make liberal use of the transient keyword so that only data that is truly needed to maintain state is sent over to the client. Anything you can re-query, or otherwise re-create, can be ditched.
Internal View State - Avoid apex components
If you're running into internal view state issues (this typically only happens with pages with large collections), the best way to reduce it is to switch to using standard HTML components instead of apex components. Each apex component adds a certain amount of "weight" to the page (and some much more than others, i.e.
