You need to sign in to do that
Don't have an account?
![Del_Santos Del_Santos](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Multiple Standard Controller
Hi,
Is it possible to use multiple standard controller in a VF page..
i.e. something like this..
<apex:page standardController="Quote" standardController="Account"
Thanks,
Del
Pradeep, I believe you are incorrect. As long as you are willing to do the initialization of the Standard Controllers object yourself instead of relying on the fields in the Page, this should be no problem. Try this.
The key is that I'm instantiating a local reference to the Account object (for example), and I'm *also* using that reference in another instantiation of a standard controller for that object. So, that gives me access to both the fields of the record using <apex:inputfield>, etc. and access to the Controller methods for that record.
So, I think this yields the behavior of multiple standard controllers within one VF page.
They key thing that's missing is that I need to load the Account records fields myself instead of having the VF mechanism automatically see that I'm using Account.Firstname, and automatically loading it for me. But, I don't see that as a huge distinction since it's declarative regardless of if it's in the Page or the Class.
Best, Steve.
p.s. My apologies for the hacked up code, I was just trying to demo it.
All Answers
There cannot be more than one standard controller in a VF page.
But can have multiple extension controllers for a page.
One way what i can suggest for the requirement you have is establish relationship in between the two objects, which will help you traversing to the data of another object.
Note that while you can only have one standard controller *defined on the <apex:page> tag*, you can have as many as you want inside your own Apex code.
So, if you declare:
<apex:page standardController="Contact" extension="myController">
and in myController do:
public with sharing class myController {
ApexPages.StandardController myAccountController;
ApexPages.StandardController myUserController;
ApexPages.StandardSetController> myOpportunitiesSetController;
ApexPages.StandardController myContactController;
myController(ApexPages.StandardController stdCntrl) {
myContactController = stdCntrl;
myAccountController = new ApexPages.StandardController([select id, Name from Account where id = :myContactController.getRecord().Account]);
myOpportunitiesSetController = new ApexPages.StandardSetController([select id, name, Amount, from Opportunity where AccountId = :myAccountController.getId()]);
//etc.
}
In short, you can use the ApexPages classes yourself for access to their methods.
Note that you could also have the illusion of multiple controllers for the same page by using Components behind the scenes.
Best, Steve.
Thanks steve for sharing valuaable information.
No, It is not possible to use multiple standard controllers in a VF page. We can inherit one standard controller at a time otherwise it will give error because we generally pass a record id of the Standard Object in URL to get all the details of that record on the VF page. You can inherit multiple custom controllers in a VF page using extensions attribute in apex page tag.
Pradeep, I believe you are incorrect. As long as you are willing to do the initialization of the Standard Controllers object yourself instead of relying on the fields in the Page, this should be no problem. Try this.
The key is that I'm instantiating a local reference to the Account object (for example), and I'm *also* using that reference in another instantiation of a standard controller for that object. So, that gives me access to both the fields of the record using <apex:inputfield>, etc. and access to the Controller methods for that record.
So, I think this yields the behavior of multiple standard controllers within one VF page.
They key thing that's missing is that I need to load the Account records fields myself instead of having the VF mechanism automatically see that I'm using Account.Firstname, and automatically loading it for me. But, I don't see that as a huge distinction since it's declarative regardless of if it's in the Page or the Class.
Best, Steve.
p.s. My apologies for the hacked up code, I was just trying to demo it.
Thanks to all..:))
I want to use in one VF page two standard controller like account and contact , but i don't want to use any extension , because it a a custom class again , i want to use only standard controller ...?
Any one have such mind to solve this