CRT-450 practice question 26 of 30

The value of the account type field is not being displayed correctly on the page. Assuming the custom controller is properly referenced on the Visualforce page, what should the developer do to correct the problem?

Full set: 201 questions
Answer options
A: Add a getter method for the actType attribute. Correct answer
B: Change theAccount attribute to public.
C: Add with sharing to the custom controller.
D: Convert theAccount.Type to a String.
Correct Answer:
A. Add a getter method for the actType attribute.
Explanation

For a Visualforce page to access and display a property from a custom controller, that property must be publicly accessible via a getter method. The Visualforce component framework uses these methods to read data from the controller. If the actType attribute is defined in the controller but lacks a public getter method (e.g., public String getActType() { ... } or is part of a public property with a {get;} accessor), the page cannot retrieve its value, resulting in it not being displayed.

References

1. Salesforce Developer Documentation

Apex Developer Guide

"Working with SOQL Queries": This section illustrates how controller properties are defined and used. It states

"To expose the results of a controller method to a page

the method must be public... For a page to be ableto use a property in a custom controller

the property needs a getter method." This directly supports option A.

Reference: Apex Developer Guide

Chapter 2: "Creating a Custom Controller"

Section: "Exposing Data to Visualforce Pages".

2. Salesforce Developer Documentation

Visualforce Developer Guide

"Custom Controllers and Controller Extensions": This guide explains the binding between Visualforce pages and Apex controllers. It details that expression language bindings like {!actType} resolve to getActType() or a public property actType with a get accessor. The absence of this getter prevents data retrieval.

Reference: Visualforce Developer Guide

Chapter 4: "Custom Controllers and Controller Extensions"

Section: "Creating a Custom Controller".

3. Salesforce Developer Documentation

Apex Developer Guide

"Using the with sharing

without sharing

and inherited sharing Keywords": This document clarifies that with sharing pertains to the enforcement of the organization's sharing model for record access

which is a different concern from property visibility for rendering on a page.

Reference: Apex Developer Guide

Chapter 6: "Security"

Section: "Using the with sharing

without sharing

and inherited sharing Keywords".

Scroll to Top