function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Steve_FinlaySteve_Finlay 

Extending a the standard controller of a custom object

Can I write a controller for a Visualforce page that 'extends' the functionality of the standardController?

 

I have a custom object, and want to add some function to that supplied by the standard controller for the custom object.

 

At the moment I am using the standard controller to access the custom objects fields and the quick save method.

 

is there something like

 

public class CustomController extends StandardController {

 

 

syntax available?

 

What is best practice for extending the functionality of a standard controller?

Best Answer chosen by Admin (Salesforce Developers) 
SargeSarge

Hi,

 

  This can be done in the following way

 

1) Create a Apex class with a parameterized constructor in this way

 

public class MyCustomController{

   public MyCustomController(ApexPages.StandardController controller){
      
   }
}

 

 

2) In Visualforce page, the <apex:page/> (starting tag) contains "standardController" attribute. use the custom object api name as value for this attribute. Also you have to set a name of apex class in the "extensions" attribute of <apex:page /> tag.

 

<apex:page standardController="Custom_Object__c" extensions="MyCustomController">

</apex:page>

 

 

By doing this you are extending the standard behaviour in the custom controller.

 

Cheers..