Activity Forums Salesforce® Discussions When should an extension be used instead of a custom controller?

  • madhulika shah

    Member
    September 12, 2018 at 6:26 am

    Hi Anjali,

    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
  • Parul

    Member
    September 12, 2018 at 9:09 am

    Hi

    Extension Controller is an Apex class that extends the functionality of a standard or custom controller.
    It helps us to leverage the built-in functionality of a standard controller but override one or more actions, such as edit, view, save, or delete.
    We can create new actions.
    If used with standard controller it respects user permissions. I.e. if used with standard controller, the logic from the controller extension 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

    Example:

    Extension controller name : StdConExtensionCon

     

    Thanks.

  • shariq

    Member
    September 12, 2018 at 2:07 pm

    Hi,

    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.

    The following are the instances where you might want to use use a extension to a standard controller:

    1. Implementing a  functionality which rely on the standard controller's behavior.
    2. To use existing functionality.
    3. To use existing actions of an object.
    4. To Run your page with applying permissions.

    Hope this helps!

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos