PDI practice question 21 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 questionsVisualforce pages access data from a custom controller through properties. A property is exposed to the page via a public getter method. The expression {!actType} on the Visualforce page specifically looks for a corresponding public method named getActType() in the controller to retrieve the value. The provided controller code has a public variable actType but lacks the required getter method. Adding a public getter method makes the actType property accessible to the page, resolving the display issue.
B. Change theAccount attribute to public. The Visualforce page references {!actType}, not {!theAccount}. Changing the visibility of theAccount does not affect the page's ability to access actType.
C. Add with sharing to the custom controller. This keyword enforces the current user's sharing rules. It addresses data visibility and security, not the data binding mechanism between the page and the controller property.
D. Convert theAccount.Type to a String. The Account.Type field, although a picklist, is already treated as a String data type within Apex. The variable actType is correctly declared as a String, so no conversion is necessary.
1. Visualforce Developer Guide, "Custom Controllers and Controller Extensions," Section: "Getter Methods"
This section explicitly states: "For every value that you want to make available for a page, you need a corresponding getter method. For example, if you have {!myValue} in your Visualforce page, the controller must have a method called getMyValue." This directly supports that a getter method is required for the {!actType} expression to function correctly.
2. Apex Developer Guide, "Classes," Section: "Defining Properties"
The documentation details how properties are defined in Apex classes, emphasizing the use of getter and setter methods to control access. It clarifies that for a Visualforce page to read a value, a public getter method is the standard implementation.
3. Apex Developer Guide, "Working with sObjects," Section: "sObject and Field Data Types in Apex"
This guide confirms that picklist fields (like Account.Type) are represented as the String data type in Apex. This validates that no type conversion is needed, making option D incorrect.
Keep practicing
Take the free PDI practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PDI practice questions
- Question 1What can be used to override the Account's standard Edit button for Lightning Experience?
- Question 4Universal Containers (UC) wants to lower its shipping cost while making the shipping proc…
- Question 5A developer has an integer variable called maxAttempts. The developer needs to ensure tha…
- Question 7Universal Containers wants to back up all of the data and attachments in its Salesforce o…
- Question 8Universal Containers hires a developer to build a custom search page to help users find t…
- Question 9As part of new feature development, a developer is asked to build a responsive applicatio…
