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
lovetolearnlovetolearn 

How to reference a standard controller and a custom controller at the same time?

I was wondering how i could ference a standard controller and a custom controller at the same time?

 

Please Help. 

 

Thanks. 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Custom controller and standard controller cannot both be defined on the apex:page component, so you'll have to set up your custom controller as an extension controller.

 

Luckily there's not too much to do.

 

Page:

 

 

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

 

 

While the controller needs an additional constructor:

 

 

public class MyCustomController
{
   ApexPages.StandardController stdCtrl;

   public MyCustomController(ApexPages.StandardController std)
   {
      stdCtrl=std;
   }
}

 

 

 

 

All Answers

Jeremy-KraybillJeremy-Kraybill

Read the section of the VF reference called "Custom Controllers and Controller Extensions". Controller Extensions is what you're looking for.

 

Jeremy

bob_buzzardbob_buzzard

Custom controller and standard controller cannot both be defined on the apex:page component, so you'll have to set up your custom controller as an extension controller.

 

Luckily there's not too much to do.

 

Page:

 

 

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

 

 

While the controller needs an additional constructor:

 

 

public class MyCustomController
{
   ApexPages.StandardController stdCtrl;

   public MyCustomController(ApexPages.StandardController std)
   {
      stdCtrl=std;
   }
}

 

 

 

 

This was selected as the best answer