Salesforce Platform Developer I (legacy) — Question 183

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

Answer options

Correct answer: C

Explanation

The correct answer is C because including <apex:messages> on the Visualforce page allows Salesforce to automatically display validation rule errors to the user. Option A is incorrect as custom controller attributes alone do not handle validation messages. Option B, while it can catch exceptions, does not specifically address validation rule violations. Option D is also incorrect because Database.upsert() does not inherently display validation errors.