I have one vf page in which I have a requirement to display huge data but as we know Vf page has View state Limit as 135 KB , hence after reaching this Limit salesforce throws Exception as "Maximum view state size limit (135KB) exceeded". So I have to show a custom Message on VF page when this limit is exceeded. Is there any way to check this limit in code? or way to throw a custom message after limit is exceeded. Thnaks In Advance.
You should take a look at following article:
The use of
transient keyword will allow you to minimize the Viewstate. Though, technically there is no known way to calculate Viewstate in visualforce via Salesforce Apex API, we just need to code within the best practices boundaries and that usually make sure that Viewstate issues never arise, also as @Mohith mentioned, clearing of Variables/List variables or variables specifically of
blob datatype (file upload controls), also minimizes Viewstate by a good margin.
Please see the answer I posted to best-practices-for-custom-controller-actions which includes a summary of view state and what impacts it most when optimizing custom controllers. In particular there's a reference to an excellent webinar on Advanced Visualforce by @PBattison that should be available for viewing any day now.