Activity › Forums › Salesforce® Discussions › How many Controllers can be used on a single Salesforce visualforce Page?
Tagged: Custom Controller, Custom Visualforce Page, Dynamic Visualforce, Inline Visualforce Page, Salesforce Apex Controller, Salesforce Controller, Salesforce Visualforce Page, Standard Controller
-
How many Controllers can be used on a single Salesforce visualforce Page?
Posted by Sanjana on July 9, 2018 at 8:15 AMHow many Controllers can be used on a single Salesforce visualforce Page?
Avnish Yadav replied 7 years, 8 months ago 6 Members · 5 Replies -
5 Replies
-
Hi sanjana
We can have only one controller at a time either it may be “StandardController” or custom Controller.And we can have as many as extensions we want.
Thank you.
- [adinserter block='9']
-
Hi,
We can use two controllers on a single salesforce visualforce page. One is controller and for custom functionality, we can use Controller extension.
Thanks.
-
Hi Sanjana,
Only one controller can be used salesforce. Other than them, Controller extension can be used. There may be more than one Controller extension.
Example-
`
`
if ExtOne and ExtTwo, both have the method getFoo() then the method of ExtOne will be executed. -
Hi,
You can have the two controller functionality in one visualforce page by using standard controller and extension. So in extension you can mention the name of multiple controller from which you want to access the functionality of these controller . For example:-
VisualForce page:-
<apex:page standardController=”Account”
extensions=”ExtOne,ExtTwo” showHeader=”false”>
<apex:outputText value=”{!foo}” />
</apex:page>Extension Class:-
ExtOne:-
public class ExtOne {
public ExtOne(ApexPages.StandardController acon) { }public String getFoo() {
return ‘foo-One’;
}
}ExtTwo:-
public class ExtTwo {
public ExtTwo(ApexPages.StandardController acon) { }public String getFoo() {
return ‘foo-Two’;
}
}Hope this helps!
-
Hello,
You can use only one controller at a times but for extensions it depends on you.
Thanks.
Log In to reply.