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
DipakDipak 

How to use More Than one controller class in a single VF page

Hi,

 

Can i use multiple controller class in a single VF page. My Vf page dont have standardcontroller , i want to use only two or more user defined controller class. Is it possible, please let me know about its syntax or solutions.

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I don't think you can specify multiple custom controllers that way - the docs say that the controller attribute takes one class name.

 

You can, however, use extensions with custom controllers in the same way as standard controllers, e.g.

 

<apex:page controller="MyCtrl" extensions="ext1, ext2">

 

Your extensions will need to have constructors that take an instance of the custom controller as a parameter.

All Answers

shruthishruthi

It is possible to use more than one controller class. You can use "Extensions"

 

This link contains an example of how to use Extensions with Standard controller. You can use it in a similar way with an ordinary Controller as well. [You cannot use a controller if you are using a standard controller and vice versa]

 

Hope this helps!

DipakDipak

Hi Shruti,

 

In the exmample, a standard controller is used. But i dont want to use any standard Controller. Can i use controller instead of standardController? I have also tried that one, But in that case, the extension Controller class Constructor takes the Controller class object as its parameter. I dont need that one. My two controller classes are independent with each other.

 

If there is  any other solution, please let me know

kiranmutturukiranmutturu

u can use like this controller="class1,class2........"

bob_buzzardbob_buzzard

I don't think you can specify multiple custom controllers that way - the docs say that the controller attribute takes one class name.

 

You can, however, use extensions with custom controllers in the same way as standard controllers, e.g.

 

<apex:page controller="MyCtrl" extensions="ext1, ext2">

 

Your extensions will need to have constructors that take an instance of the custom controller as a parameter.

This was selected as the best answer
DipakDipak

Thanks Bub,

 

You are absolutely right. Thanks a lot for your suggestion.

 

If i am not going to use the constuctor of extension controller having parameter as controller class instance, then it is not possibel to achieve that one.

 

So i used one controller class, and from that controller , another class method(i.e the 2nd controller) is called. 

After that my code is working perfectly..

 

Thanks all for your help

kiranmutturukiranmutturu

ya sorry i mistakely right the above post... ya its extension where you can give more than one class....