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
sparkysparky 

extend VF controller class?

Is it possible to write a class that extends a custom VF controller, and then use the new class as the controller for a page?  Can I extend a class that is itself an extension of a standard controller, as opposed to a fully-custom controller?

 

It's the latter that I'm trying to do right now.

 

I tried creating an extension.  I added the "virtual" keyword to my existing controller, then defined a new child class something like so:

 

public class CTRL_CustomWizard extends CTRL_FooWizard {

 

 but I get the error "Parent class has no 0-argument constructor for implicit construction"

 

 

 Does this mean I can't do it, or do I need to do something else?  The constructor in the parent class can't have no arguments, because it's an extension of a standard controller, so the constructor is defined like:

 

public CTRL_FooWizard (ApexPages.StandardController controller) {

 

Thanks much!

 

Message Edited by sparky on 05-28-2009 10:50 PM
Best Answer chosen by Admin (Salesforce Developers) 
sparkysparky

 So I think I got this to work.  At least I got it to compile. 

I used this construction:

 

 

public class GPTF_CTRL_NewOpp extends ONEN_CTRL_NewOppWizard { public GPTF_CTRL_NewOpp (ApexPages.StandardController controller) { super (controller); } }

 

 Does that look right?  I'll see if it works when it's really used in a VF pg.

 

All Answers

dmsx2oddmsx2od

Matthew-

Just taking a stab at it:

I wonder if you can do something like in Java, where you'd have to make a call to the parent in the child constructor:

super( <something );

Not sure how to pass the standard controller or how you'd refer to it, but since the superclass requires you to pass something of type ApexPages.StandardController, I wonder if you would need to specify the sObject.

Hope that helps,

David

sparkysparky

 So I think I got this to work.  At least I got it to compile. 

I used this construction:

 

 

public class GPTF_CTRL_NewOpp extends ONEN_CTRL_NewOppWizard { public GPTF_CTRL_NewOpp (ApexPages.StandardController controller) { super (controller); } }

 

 Does that look right?  I'll see if it works when it's really used in a VF pg.

 

This was selected as the best answer
dmsx2oddmsx2od
Yes, that's how I'd try it (in theory) - please let us know how it goes.
adiezadiez

Hi Sparky.

are you using a standard controller in your FV pages? I am understanding you want extend a standard controller like Account or Contact, so you should have put this on your VF page:

 

<apex:page standardController="Account" extensions="myExtensionController">
...
</apex:page>

 

 You try to put this on your controller:

 

public class myExtensionController{
//Case Account
public Account accFinal {get{return this.accFinal;}set;}
//contructor

public myExtensionController(ApexPages.StandardController controller){
this.accFinal = (Account) controller.getRecord();
...
}

...
}

 

 by this way, it provided you a extensions for your standard controller... and pardon for my english, I hope you can understand me.

adiez
Salesforce Consulting Partner in Spain

www.proclientia.com

 

 

JasonLincolnJasonLincoln

Are there any examples where the standard controller methods are used by an extension controller class where the returned PageReference is not what the standard controller returns?

 

I'd like to know if I can use the standard controller methods like save but keep control of the UI and not get redirected to the standard SF page returned by the standard controller's save method.

 

Thanks,

Jason