Plat-Dev-301 practice question 4 of 10

There is an Apex controller and a Visualforce page in an org that displays records with a custom filter consisting of a combination of picklist…

Full set: 160 questions
There is an Apex controller and a Visualforce page in an org that displays records with a custom filter consisting of a combination of picklist values selected by the user. The page takes too long to display results for some of the input combinations, while for other input choices it throws the exception, "Maximum view state size limit exceeded". What step should the developer take to resolve this issue?
Answer options
A: Adjust any code that filters by picklist values since they are not indexed.
B: Remove instances of the transient keyword from the Apex controller to avoid the view state error.
C: Split the layout to filter records in one Visualforce page and display the list of records in a second page using the same Apex controller.
D: Use a StandardSetController or SOQL LIMIT in the Apex controller to limit the number of records displayed at a time. Correct answer
Correct Answer:
D. Use a StandardSetController or SOQL LIMIT in the Apex controller to limit the number of records displayed at a time.
Explanation

The scenario describes two related problems: slow performance and exceeding the view state size limit (135 KB). Both issues stem from querying and attempting to manage too large a record set in the controller's memory. A StandardSetController is the idiomatic Visualforce solution for handling large data sets, as it provides built-in pagination and manages record retrieval in batches, keeping the view state small. Alternatively, manually adding a LIMIT clause to the SOQL query in a custom controller achieves a similar outcome by restricting the number of records returned, thus reducing both query time and view state size.

Why Incorrect

A. Standard picklists are indexed. Assuming the filter uses non-indexed fields is a premature conclusion; the core issue is the volume of data returned, not necessarily the filter field type.
B. The transient keyword reduces view state by excluding a variable from serialization. Removing it would worsen the "Maximum view state size limit exceeded" error.
C. Splitting the page does not solve the underlying problem. The controller would still fetch a large dataset, causing the same performance and view state issues on the results page.

References

1. Salesforce Apex Developer Guide, "Working with Large Sets of Data," section on StandardSetController. It explicitly states, "Standard set controllers... allow you to create list controllers that can display and act on a set of records, such as in a list page with pagination."

2. Salesforce Visualforce Developer Guide, "Best Practices for Improving Visualforce Performance," section "Reduce View State". It recommends using StandardSetController or limiting data to reduce view state.

3. Salesforce SOQL and SOSL Reference, "LIMIT Clause". The documentation describes how LIMIT restricts the number of rows returned, which is a direct way to control data volume.

Scroll to Top