A custom controller is simply an Apex class. For example, the following code is a valid, though ineffective,
controller class:
public class MyController {
}
You can create a controller class and add it to your page in two
different ways:
- Add the controller attribute to your page and use a “quick
fix” to create the controller class on the fly:
- In the page editor, add the controller attribute to the <apex:page> tag. For example:
<apex:page controller="MyController">
<apex:pageBlock title="Hello {!$User.FirstName}!">
This is your new page.
</apex:pageBlock>
</apex:page>
- Use the quick fix option to automatically create a new Apex class named MyController.
- Create and save the controller class in the Apex editor of your choice, and then reference it in your page:
- In the application, from Setup, enter “Apex Classes” in the Quick Find box, then select Apex Classes and click New to create a new class.
- Return to your page and add the controller attribute to the <apex:page> tag as described in the example above.
As soon as you save a page that references a valid custom controller,
a second Controller editor tab is available next to the Page Editor.
This editor allows you to toggle back and forth between your page
markup and the Apex that defines the page’s logic.
The Custom
Controller Editor