nerdexam
Salesforce

PDI · Question #197

A developer created a Visualforce page and custom controller to display the account type field as shown below. Custom controller code: Visualforce page snippet: The value of the account type field…

The correct answer is D. Add a getter method for the actType attribute. For a Visualforce page to display the value of a non-property variable like actType in a custom controller, an explicit getter method must be defined for that variable.

Submitted by stefanr· Apr 18, 2026User Interface

Question

A developer created a Visualforce page and custom controller to display the account type field as shown below. Custom controller code:

Visualforce page snippet:

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?

Exhibit

PDI question #197 exhibit

Options

  • AConvert theAcccunt, type to a String.
  • BChange theAccount attribute to public.
  • CAdd with sharing to the custom controller.
  • DAdd a getter method for the actType attribute.

How the community answered

(26 responses)
  • A
    8% (2)
  • B
    15% (4)
  • C
    4% (1)
  • D
    73% (19)

Why each option

For a Visualforce page to display the value of a non-property variable like `actType` in a custom controller, an explicit getter method must be defined for that variable.

AConvert theAcccunt, type to a String.

Converting `theAccount.type` to a String is unnecessary; the issue is accessing the value of `actType`, not the data type of `theAccount.type`.

BChange theAccount attribute to public.

The `theAccount` attribute is already accessible if declared with `get; set;` or explicitly as `public`, and this change would not resolve the problem of `actType` not being displayed.

CAdd with sharing to the custom controller.

Adding `with sharing` to the custom controller affects record access based on the running user's permissions but does not determine whether a controller variable's value can be displayed on a Visualforce page.

DAdd a getter method for the actType attribute.Correct

Visualforce pages rely on getter methods to retrieve the values of properties from Apex controllers. If `actType` is declared as `public String actType;` without a `{get; set;}` declaration, it requires an explicit `public String getActType() { return this.actType; }` method for the Visualforce page to successfully read and display its value.

Concept tested: Visualforce controller getter methods

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_vf_custom_controller.htm

Topics

#Visualforce#Apex Controller#Data Binding#Getters and Setters

Community Discussion

No community discussion yet for this question.

Full PDI Practice