nerdexam
Salesforce

PDI · Question #5

A developer has a Visualforce page and custom controller to save Account records. The developer wants to display any validation rule violation to the user. How can the developer make sure that validat

The correct answer is B. Include <apex:message> on the Visualforce page.. The developer wants to display validation rule violations from a custom controller to a Visualforce page when saving Account records.

Submitted by tarun92· Apr 18, 2026User Interface

Question

A developer has a Visualforce page and custom controller to save Account records. The developer wants to display any validation rule violation to the user. How can the developer make sure that validation rule violations are displayed?

Options

  • AAdd cuatom controller attributes to display the message.
  • BInclude apex:message on the Visualforce page.
  • CUse a try/catch with a custom exception class.
  • DPerform the DML using the Database.upsert() method.

How the community answered

(26 responses)
  • A
    8% (2)
  • B
    88% (23)
  • D
    4% (1)

Why each option

The developer wants to display validation rule violations from a custom controller to a Visualforce page when saving Account records.

AAdd cuatom controller attributes to display the message.

Custom controller attributes are not the standard or simplest way to display system-generated validation rule messages; Visualforce provides dedicated components for this purpose.

BInclude <apex:message> on the Visualforce page.Correct

The `<apex:message>` or `<apex:messages>` Visualforce components are designed to automatically display all error messages, including those generated by standard validation rules and Apex `addError()` calls, when a DML operation fails due to validation.

CUse a try/catch with a custom exception class.

While `try/catch` blocks handle exceptions, validation rule violations are platform-level errors that are best displayed using `<apex:messages>` or `<apex:message>` directly, rather than relying on a custom exception class for this specific scenario.

DPerform the DML using the Database.upsert() method.

`Database.upsert()` is a DML operation for inserting or updating records, but it does not inherently handle the display of validation errors on a Visualforce page; it would return `Database.SaveResult` objects that would need manual processing to extract and display errors.

Concept tested: Visualforce error message display

Source: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_messages.htm

Topics

#Visualforce#Error Handling#Validation Rules#User Interface

Community Discussion

No community discussion yet for this question.

Full PDI Practice