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
prasad p 18prasad p 18 

how to overcome the view state exception?

Khan AnasKhan Anas (Salesforce Developers) 
Hi Prasad,

Greetings to you!

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. Decide if some data can be read-only and use the <apex:outputText> component instead of <apex:inputField>.
  • Set the Development Mode and Show View State in Development Mode permissions set to see the View State tab in the development mode footer. The tab displays the distribution of view state. Make sure you know the view state size of each page, and test with large data volumes to determine if issues might occur after deployment.
  • Use JavaScript remoting. Unlike the <apex:actionFunction> component, JavaScript Remoting does not require a form component. This technique doesn’t reduce the overall view state of a page, but your page generally performs better without the need to transmit, serialize, and deserialize the view state. The tradeoff is the loss of the re-render attribute and the additional JavaScript code to handle callbacks.

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

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

https://developer.salesforce.com/docs/atlas.en-us.salesforce_visualforce_best_practices.meta/salesforce_visualforce_best_practices/pages_best_practices_perf_code_view_state.htm

https://www.brcline.com/blog/how-to-reduce-salesforce-view-state

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

https://www.jitendrazaa.com/blog/salesforce/introduction-to-view-state-in-visualforce/

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