Plat-Dev-301 practice question 5 of 10

A developer created and tested a Visualforce page in their developer sandbox, but now receives reports that users encounter "View State" errors when using it in production. What should the developer ensure to correct these errors?

Full set: 160 questions
Answer options
A: Ensure profiles have access to the Visualforce page.
B: Ensure properties are marked as private.
C: Ensure variables are marked as transient.12 Correct answer
D: Ensure queries do not exceed governor limits.34
Correct Answer:
C. Ensure variables are marked as transient.12
Explanation

A "View State" error occurs when the data stored in a Visualforce page's state exceeds the 170KB limit. This state includes controller properties and component trees needed to maintain the page's state between server requests. The transient keyword is the specific Apex feature designed to solve this. By declaring a variable as transient, a developer instructs the platform to exclude it from the view state, thus reducing its size. This is appropriate for variables that are not needed across postbacks or can be easily reconstructed.

Why Incorrect

A. Profile access issues would result in an "Insufficient Privileges" error, not a View State error.
B. The private access modifier controls code visibility, but does not prevent a variable from being included in the view state if it's accessed by the page.
D. Exceeding governor limits, such as the number of SOQL queries, results in a LimitException, which is a different error from a View State size error.

References

1. Visualforce Developer Guide, "Understanding Visualforce View State", Section: "Best Practices for Reducing View State". The guide explicitly states, "Use the transient keyword for variables that are not essential for maintaining the page’s state and can be reconstructed."

2. Apex Developer Guide, "Using the transient Keyword". This section details how the keyword prevents fields from being saved as part of the view state.

Scroll to Top