Custom controllers are used to implement the logic and functionality without using a standard controller and controller extensions are used to extend the logic and functionality of a standard controller or a custom controller. Custom controllers and Controller extension are written using Apex.
What is Controller in Salesforce ?
A Controller is set of instructions that can react on the user’s interaction with Visualforce page action (for example, a button click or a link click) to give the required output. A controller can control the behavior of a page and it can be used to access the data which should be displayed on the page.
What is Extensions in Salesforce ?
A controller extension is an Apex class that extends the logic and functionality of a standard or custom controller. Use controller extensions when you want to –
- Keep the majority of built-in functionality of a standard or custom controller as it, is and add more functionality or override any functionality
- 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.
Note – Only one controller can be used in a particular page.
A custom controller uses a non-parameterized constructor. You cannot create a constructor that includes parameters for a custom controller.
Note – A controller extension uses one-parameterized constructor with the Apex pages StandardController type of argument or a custom controller type.