,

Creating a Controller Extension

Your next step is to create a controller extension to provide the new functionality for the Visualforce page.

The controller extension is an Apex class, which you learned about in the previous two chapters.

1.
Create a new Apex class through clicking on the Setup Develop Apex Classes New button.

2.
Add the following code to begin the creation of your controller extension:

public class positionExtension {
}

The initial code for this class should be familiar to you from the previous two chapters. You simply begin the class by identifying it and creating the pair of brackets that enclose the code.

3.
Add the following line of code to the class:

public class positionExtension {
private final Position__c position;
}

This line of code is one of the two ways that you will tie your controller extension to the standard controller. The code creates an sObject with the structure of the Position__c object, and gives that object the name of position. This object will only be accessible to methods inside this class, so it is defined as private.

4.
Add the highlighted code to the class:

public class positionExtension {
private final Position__c position;
public positionExtension(ApexPages.StandardController
								positionController) {
								this.position =
								(Position__c)positionController.getRecord();
								}
}

This second step creates a controller extension object and then loads the position record with the current record used by the standard controller for the Position__c controller. The position variable is now tied to the same record as the standard controller, allowing the controller extension to operate in synch with the standard controller.

You have successfully created the shell of a controller extension. Your next step is to add the functionality you need to offer to your Visualforce page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.106.33