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:
public class Mycustomcontroller {
}
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="Mycustomcontroller">
<apex:pageblock title="Hello {!$User.FirstName}">
This is my new page
</apex:pageblock>
</apex:page>
2.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 Newto create a new class.
- Return to your page and add the controller attribute to the <apex:page> tag as described in the example above.
Note : A page can only reference one controller at a time. You can’t use both the standardController attribute and the controller attribute in an <apex:page> tag.
No comments:
Post a Comment