You just call the constructor and mention the parameters like this public class myControllerExtension { public myControllerExtension(ApexPages.StandardController stdController) { } }
Extension for Custom Controller in class
There is two type of methods: See the Example on below: 1) public class myControllerExtension { public myControllerExtension(ApexPages.StandardController controllerParam) { } }
public with sharing class MyApexClass { private ApexPages.StandardController ctrl; public Custom__C custm {get;set;} public MyApexClass() { try { acct = [select Name from Custom__C where Id = : ApexPages.currentPage().getParameters().get('id')]; } catch (QueryException e) { custm = new Custom__C(); } ctrl = new ApexPages.StandardController(custm); }
In addition to Pratik's answer, a controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.StandardController or CustomControllerName, where CustomControllerName is the name of a custom controller you want to extend.
Simple example:
public class myControllerExtension {
private final Account acct;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public myControllerExtension(ApexPages.StandardController stdController) {
this.acct = (Account)stdController.getRecord();
}
public String getGreeting() {
return 'Hello ' + acct.name + ' (' + acct.id + ')';
}
}
You just call the constructor and mention the parameters like this public class myControllerExtension { public myControllerExtension(ApexPages.StandardController stdController) { } }
Extension for Custom Controller in class
There is two type of methods: See the Example on below: 1) public class myControllerExtension { public myControllerExtension(ApexPages.StandardController controllerParam) { } }
public with sharing class MyApexClass { private ApexPages.StandardController ctrl; public Custom__C custm {get;set;} public MyApexClass() { try { acct = [select Name from Custom__C where Id = : ApexPages.currentPage().getParameters().get('id')]; } catch (QueryException e) { custm = new Custom__C(); } ctrl = new ApexPages.StandardController(custm); }
Extension for standard controller in class:
You just call the constructor and mention the parameters like this
public class myControllerExtension
{
public myControllerExtension(ApexPages.StandardController stdController)
{
}
}
Extension for Custom Controller in class
There is two type of methods:
See the Example on below:
1)
public class myControllerExtension
{
public myControllerExtension(ApexPages.StandardController controllerParam)
{
}
}
2)
<apex:page controller="Custom__C" Extension= "MyApexClass"> ... </apex:page>
public with sharing class MyApexClass
{
private ApexPages.StandardController ctrl;
public Custom__C custm {get;set;}
public MyApexClass()
{
try
{
acct = [select Name from Custom__C where Id = : ApexPages.currentPage().getParameters().get('id')];
}
catch (QueryException e)
{
custm = new Custom__C();
}
ctrl = new ApexPages.StandardController(custm);
}
Thanks & Regards,
Viswanadh
All Answers
Extension to a controller is an apex class. You can invoke/call the extension in visualforce page in <apex:page> tag.
<apex:page controller="controllername" extensions=" extensionclassname">
</apex:page>
Let me know if need any further help.
Thanks,
Pratik
In addition to Pratik's answer, a controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.StandardController or CustomControllerName, where CustomControllerName is the name of a custom controller you want to extend.
Simple example:
Read the full article here: http://www.salesforce.com/docs/developer/pages/Content/pages_controller_extension.htm (http://www.salesforce.com/docs/developer/pages/Content/pages_controller_extension.htm" target="_blank)
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Extension for standard controller in class:
You just call the constructor and mention the parameters like this
public class myControllerExtension
{
public myControllerExtension(ApexPages.StandardController stdController)
{
}
}
Extension for Custom Controller in class
There is two type of methods:
See the Example on below:
1)
public class myControllerExtension
{
public myControllerExtension(ApexPages.StandardController controllerParam)
{
}
}
2)
<apex:page controller="Custom__C" Extension= "MyApexClass"> ... </apex:page>
public with sharing class MyApexClass
{
private ApexPages.StandardController ctrl;
public Custom__C custm {get;set;}
public MyApexClass()
{
try
{
acct = [select Name from Custom__C where Id = : ApexPages.currentPage().getParameters().get('id')];
}
catch (QueryException e)
{
custm = new Custom__C();
}
ctrl = new ApexPages.StandardController(custm);
}
Thanks & Regards,
Viswanadh