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
SimrinSimrin 

Resuing code in an application

I have 3 pages which does nearly sale thing, I have created 3 pages and 3 respective controllers.
Is there way i could reuse my visualfoce page and controller.
Best Answer chosen by Simrin
BDatlaBDatla
Hi Simrin,

1) the best practice would be creating the components and include them in the respective visualforce page.
2) Create a separate class for the funtionality and call them in the controller,This will help to reuse the same code for similar functionality.

Regards,
BDatla

All Answers

BDatlaBDatla
Hi Simrin,

1) the best practice would be creating the components and include them in the respective visualforce page.
2) Create a separate class for the funtionality and call them in the controller,This will help to reuse the same code for similar functionality.

Regards,
BDatla
This was selected as the best answer
SimrinSimrin

1) is understood
2) you try to say that, I create a Class with all the fucntionalities and when i want to use the functionality, i will create object of this class and use the fucntiuuons inside it.

Also, Can i use the same controller for 3 different pages. If i can, are there no conflicts during usage of page.  what will be the scope in this case.

BDatlaBDatla
The scope will be separate for each controller instance.
Are you trying to achive wizard control ? Are just want to use the same controller for all the 3 pages ?
You can use the same controller and use an extensioncontroller to add any more functionalities.

Regards,
BDatla
SimrinSimrin

I have page which derives information from controller and displays and also is information is modified on screen it is saved back to controller.

Based on your comments,

Page 1 - Controller1
Page 2- Controller2
Page 3 - Controller3

controller 4 for Common functionalities(used by all 3 other controllers)

Do you think, this is right logically

BDatlaBDatla
Hi Simrin,

Yes, I think it is right logically assuming 4th one is main controller and remaining are controller extensions.

Regards,
BDatla