Editing a record and its parent

A Visualforce page managed by a standard controller can provide the edit capability for a record and its parent. However, when the standard controller Save method is invoked, the object graph is not traversed and only the record being managed by the controller is saved.

In this recipe, we will create a Visualforce page to allow a user to edit fields from a contact and its parent account. Saving the record will also apply any changes made to the parent account record.

Getting ready

This recipe makes use of an extension controller, so this will need to be created before the Visualforce page.

How to do it...

  1. First, create the custom controller by navigating to the Apex Classes setup page by clicking on Your Name | Setup ...

Get Visualforce Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.