Inspect what is in your page View State, identify the largest contributors, and apply the standard fixes (transient, pagination, read-only mode) to bring the page under 170 KB.
- Enable development mode
On your user record, set the Development Mode flag. Open the Visualforce page; a footer at the bottom now exposes the View State inspector link.
- Open the View State inspector
Click the View State tab in the footer. The inspector lists every node in the serialized graph with its byte size, sorted descending. The top three entries are usually where the budget is going.
- Mark large transient candidates
For each controller variable holding a derived list or a large string, add the transient keyword to the field declaration. Recompute it inside the getter so the page still works. Re-run the inspector; the variable should drop to zero.
- Paginate large result sets
Replace the SOQL query that fetched all records with a StandardSetController or an explicit LIMIT/OFFSET. Hold only the current page in memory. Add Next and Previous action buttons that re-execute the query.
- Switch to read-only mode if data is display-only
Add readOnly="true" on the apex:page tag. Confirm no DML operations exist on the page. Re-test to make sure the page still renders.
- Confirm under 170 KB
Re-run the View State inspector. Verify the total is below 170 KB with at least 20 KB of headroom for future data growth.
Field modifier that excludes a controller variable from the serialized View State. Trade-off is the variable is recomputed each postback.
Page-level setting that disables DML, lifts the 50k SOQL row cap to 1M, and trims state overhead.
Built-in controller that paginates large result sets automatically and keeps only one page's records in memory.
Footer-level tool surfaced under Development Mode that breaks down serialized state by node and size.
- Static variables do not contribute to View State, but they also do not persist across requests. Do not use static fields to dodge the limit; the values reset on every postback.
- Marking a variable transient means it is recomputed on every request. If the recomputation costs a SOQL query and that query is now in a loop on a Repeater, you can trade a View State error for a SOQL governor error.
- ApexPages.StandardSetController serializes its own state into View State for navigation. On very large result sets the controller itself can become the bloat source.
- The 170 KB limit is post-compression. A page that shows 165 KB in the inspector is one user action away from blowing through the limit; design with 20 KB headroom.