function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nikhil NNikhil N 

when i dispalying more than 1k records get "view state" error,So please help how to avoid "View State" error in visualforce page????

Khan AnasKhan Anas (Salesforce Developers) 
Hi Nikhil,

Greetings to you!

If your collection size is running into limits, you will need to implement pagination. Visualforce is not designed to display more than 1000 records on the same page. If your SOQL's are returning more than 1000 records and you attempt to display these records on a VF page, you will receive this error.

1. You can either limit the number of records you are trying to display to be less than 1000 or use pagination to display the records in different pages

2. You can use the @ReadOnly annotation on the method that retrieves the records or on the entire visualforce page. But you will not be able to perform DML operations when you execute a transaction.

3. Query fewer records or set a row limit. And query fewer fields per record.

Please refer to the below links which might help you further with the above requirement.

https://saramorgan.net/2015/09/06/understanding-and-monitoring-visualforce-view-state/

https://help.salesforce.com/articleView?id=000221049&type=1

https://help.salesforce.com/articleView?id=000002955&type=1

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Nikhil NNikhil N
Hi Khan Anas,
I implemented this scenario by using pagination only but when i display more than 1000 records still getting "View State" error.
Khan AnasKhan Anas (Salesforce Developers) 
Please refer to the below link with a similar discussion:

https://developer.salesforce.com/forums/?id=906F00000008zd8IAA

Regards,
Khan Anas
mukesh guptamukesh gupta
Hi Nikhil,

You can use 

@Readonly
Basically we use this where VF page comes in picture and you want to display a list of records on page.
By default if if you are using a list on VF page, that cannot hold more than 1000 records. But @readOnly increases this limit to 10,000. But you cannot perform any DML operation on this list.

@Future:
Methods with the future annotation must be static methods, and can only return a void type.
The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types. Methods with the future annotation cannot take SObjects or objects as arguments.
Specify (callout=true) to allow callouts in a future method. Specify (callout=false) to prevent a method from making callouts.
@future (callout=true)
Public static void doCalloutFromFuture() {
   //Add code to perform callout
}

Kindly MARK AS A BEST ANSWER!!if the reply was helpful.


Regards
Mukesh

 
Nikhil NNikhil N
Hi Mukesh,

I tried by using "readOnly=true" in VF Page, when i update any record getting "To many DML Statement" Error,if i update a record without using "readOnly=false" record is updating but when i display more than 1000 records i am getting "View State" error.So please help me how to avoid the "View State" error.
Nikhil NNikhil N
Please help how to avoid "View State" error in visualforce page