If your page is for displaying or editing information about a particular type of record, it may be helpful to use a standard controller to reduce the amount of boilerplate code you need to write.
By using a standard controller, your page will be displayed with an ?id=SALESFORCE_ID
parameter, and you automatically get access to all merge fields on the record.
Add a standard controller to your page by specifying the standardController
attribute on <apex:page>
:
<apex:page standardController="Account">
This is a page for {!Account.Name}
</apex:page>
You also get the standard controller methods for free:
cancel()
- returns the PageReference
for the cancel page (usually navigates back to a list view)delete()
- deletes the record and returns the PageReference
for the delete pageedit()
- returns the PageReference
for the standard edit pagesave()
- saves the record and returns the PageReference
to the updated recordview()
- returns the PageReference
for the standard view pageYou can use them like this:
<apex:page standardController="Account">
Name: <apex:inputField value="{!Account.Name}" />
<apex:commandButton value="Update record" action="{!save}" />
</apex:page>