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
Narasimha LNarasimha L 

-When should an Extension be used instead of a Custom Controller?

Hi Dev's

-When should an Extension be used instead of a Custom Controller?


Regards
Narasimha
Best Answer chosen by Narasimha L
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same
1) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller.htm
2) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_def.htm
3) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_considerations.htm
4) https://www.lynda.com/Visualforce-tutorials/Understanding-standard-controllers-custom-controllers-extensions/172850/197247-4.html
5) http://www.slideshare.net/msabukwaik/custom-controllers-and-controller-extensions

What are Custom Controllers and Controller Extensions?
A custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller. Use custom controllers when you want your Visualforce page to run entirely in system mode, which does not enforce the permissions and field-level security of the current user.
A controller extension is an Apex class that extends the functionality of a standard or custom controller. Use controller extensions when:
  • You want to leverage the built-in functionality of a standard controller but override one or more actions, such as edit, view, save, or delete.
  • You want to add new actions.
  • You want to build a Visualforce page that respects user permissions. Although a controller extension class executes in system mode, if a controller extension extends a standard controller, the logic from the standard controller does not execute in system mode. Instead, it executes in user mode, in which permissions, field-level security, and sharing rules of the current user apply

 

All Answers

RD@SFRD@SF
Hi Narasimha

An extension controller is used when you want to have custom fucntion in the controller. As you would know salesforce works as a MVC. Model, view and controller. Each object created in salesforce has a standard controller with basic functions like save, cancel.

If you want to have a custom save methods or your own methods an extension class is used to achieve that

Hope it gives a basic idea

RD
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same
1) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller.htm
2) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_def.htm
3) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_considerations.htm
4) https://www.lynda.com/Visualforce-tutorials/Understanding-standard-controllers-custom-controllers-extensions/172850/197247-4.html
5) http://www.slideshare.net/msabukwaik/custom-controllers-and-controller-extensions

What are Custom Controllers and Controller Extensions?
A custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller. Use custom controllers when you want your Visualforce page to run entirely in system mode, which does not enforce the permissions and field-level security of the current user.
A controller extension is an Apex class that extends the functionality of a standard or custom controller. Use controller extensions when:
  • You want to leverage the built-in functionality of a standard controller but override one or more actions, such as edit, view, save, or delete.
  • You want to add new actions.
  • You want to build a Visualforce page that respects user permissions. Although a controller extension class executes in system mode, if a controller extension extends a standard controller, the logic from the standard controller does not execute in system mode. Instead, it executes in user mode, in which permissions, field-level security, and sharing rules of the current user apply

 
This was selected as the best answer