Newer Version Available
Creating a Custom Controller Class
A custom controller is simply an Apex class. For example, the following code is a valid, though ineffective, controller class:
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:
- Use the quick fix option to automatically create a new Apex class named MyController.
- In the page editor, add the controller attribute to the <apex:page> tag. For example:
- 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.
