Slaesforce FAQ

how to avoid view state error in salesforce using pagination

by Prof. Gwen Will II Published 3 years ago Updated 2 years ago
image

To reduce view state: Use filters and pagination to reduce data requiring state. Declare instance variables with a transient keyword when the variable is only useful for the current request. The view state includes all non-transient members in the controller and extension, as well as objects reachable from these non-transient members.

Full Answer

What is view state error in Salesforce?

View State: As the name suggests, it is an error of View State. Maximum view state size limit (135KB) exceeded is the error message pertaining to View State error and here follows a brief detailing of the issue. View state holds the state/size of the visual force page that includes the components, field values, and controller state.

How do I maintain state in a Visualforce page?

To maintain state in a Visualforce page, the Lightning Platform platform includes the state of components, field values, and controller state in a hidden form element. This encrypted string is the view state and has a limit of 170KB.

What is the size of a page in Salesforce?

This is important in the light that salesforce provides only a standard size of 135kb for any individual page. If the size of a particular page exceeds 135kb, the page will throw a view state error.

What is the maximum view state size limit in Salesforce?

Finally there’s some sort of internal state that Salesforce doesn’t provide much information about. In Salesforce, the view state needs to be less than 135kb or you will get an exception.The error message will look something like this and be displayed to the end user: “Maximum view state size limit (135KB) exceeded.

image

How do I reduce view state error in salesforce?

In order to reduce the view state, make use of the following:"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 on a page. ... Refine your SOQL to retrieve only the data needed.More items...

How do I use pagination in salesforce?

Pagination is the process of displaying large number of records and displaying the records on multiple pages within in Salesforce. In order to control the number of records displayed on each page, we use pagination. By default, a list controller returns 20 records on the page.

How do I enable view state in salesforce?

To enable the View State tab:From 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 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 is pagination used in lightning component?

Pagination Using Lightning ComponentsStep 1: Go to Setup -> Developer Console -> File -> New -> Lightning Component -> Enter the lightning component name as “Opportunity_PaginationTable”.Note:Opportunity_PaginationTable.cmp.Step 2: Create a Client-Side Controller.Step 3: Create an Apex Class.OpportunityController_AC.More items...

What is the difference between rendered and ReRender?

Rendered-This attribute is used to display a particular filed or section based on boolean value. ReRender- This is to reload some fields, or sections after some operation. Advantage of it is that the whole page is not refreshed and only a portion(the one which is ReRendered) is refreshed.

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.

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 viewstate VF page?

View state holds the state/size of the visual force page that includes the components, field values, and controller state. This is important in the light that salesforce provides only a standard size of 135kb for any individual page.

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.

What is the use of action Poller?

Action poller acts as a timer in visualforce page. It is used to send an AJAX request to the server depending on the time interval (time interval has to be specified or else it defaults to 60 seconds). In the action attribute a controller method gets called.

What's the disadvantages of using transient keyword?

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.

How to keep VF page size small?

1. Use the transient keyword: The simplest and the most logical way is to keep the size of the VF page as small as possible. For this purpose, Transient Variables are used as these do not store the values permanently, these variables just hold the values temporarily and therefore not stored in View State.

Can you have multiple forms on a page?

Instead of having multiple forms on a page, have a single form and use <apex:actionRegion> to submit portions of the form. This will make sure only a single copy of the view state is associated with that VF page instead of two copies. Eg:

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.

What is view state in Salesforce?

View State is a technique Salesforce uses to maintain the current state of the page and the data that was queried between the user requesting things from the server and sending any changes back to the server.If the view state gets too large problems can begin to occur. The view state is an encrypted field that contains the following data: 1 All of the non-transient data that is in the associated controller and any associated controller extensions 2 State related to all of the form elements and components that are used on the page. 3 Finally there’s some sort of internal state that Salesforce doesn’t provide much information about.

Why is view state important?

The reason that the view state is so important is that because every time the page is re-rendered for some reason or that a request has been sent to the server that we need to send and receive the view state. As you can imagine, a large view state being constantly transmitted would add a lot of overhead.

image
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9