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
Ayush Jain 116Ayush Jain 116 

Maximum View state size limit (170K) exceeded error

I have created a invoice creation page using VF page, for smaller data it is working fine but for larger data it is giving above error. 

Can i increase this limit or what should i do ?

SubratSubrat (Salesforce Developers) 
Hello Ayush ,

You're basically trying to store every record in the database in the view state. Check about dynamic queries (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm) and this will greatly improve your code's performance and allow you to avoid view state size errors, heap limit exceptions, CPU timeouts, too many query rows, etc.

Check below reference for debugging size limit error.

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

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

If this helps , please mark this as best answer.

Thank you.