You need to sign in to do that
Don't have an account?

Standard controller and custom controller in one apex page
I have a custom controller and apex page associated with it. I am posting the page with button click in account page layout. When my apex page is displayed I want to display some values from account object like name, city. my customer controller with all the logic in it and works fine.
1. My page starts with the line
<apex:page Controller="MyCustomSelController">
Can I add StandardController = "Account" to get the account fields?
2. How do I use standardController and pass the values to my custom controller?
Thanks
Uma
You should have a controller variable in your custom controller class and you should set that member variable to the inbound controller. like so:
public class MyCustomController{
private final ApexPages.StandardController controller;
public MyCustomController(ApexPages.StandardController controller){
this.controller = controller;
}
}
Anything you wish to initialize you'll need to add to the constructor that the vf page uses (it always uses the one with a controller, whether a standardcontroller or standardsetcontroller)
All Answers
Use your Custom controller as an extension
<apex:page standardController = "Account" extensions="myCustomController">
</apex:page>
Thanks for the quick response.
do I have to modify my controller to add another contructor? I am getting the following error?
Error: Unknown constructor 'MyCustomSelController.MyCustomSelController(ApexPages.StandardController controller)'
do I have to change any code, besides adding a contructor?
You should have a controller variable in your custom controller class and you should set that member variable to the inbound controller. like so:
public class MyCustomController{
private final ApexPages.StandardController controller;
public MyCustomController(ApexPages.StandardController controller){
this.controller = controller;
}
}
Anything you wish to initialize you'll need to add to the constructor that the vf page uses (it always uses the one with a controller, whether a standardcontroller or standardsetcontroller)
Thanks for the quick response. Here is the final code that worked.
public class MyCustomController{
public MyCustomController() {}
private final ApexPages.StandardController controller;
public MyCustomController(ApexPages.StandardController controller){
this.stdAcctController = (Account)stdcontroller.getRecord();
}
}
Thank you so much.