Activity Forums Salesforce® Discussions Can anyone compare and contrast custom controllers & controller extensions in Salesforce?

  • Avnish Yadav

    Member
    July 30, 2018 at 4:19 am

    Hello Chanchal,

    Standard controllers can often provide all of the functionality and data that you need for your Visualforce page.

    However, you may need to start coding your own controller code if you want then its Custom controller

    1. Override existing functionality
    2. Make new actions available to the page
    3. Customize the navigation
    4. Use HTTP callouts or web services
    5. Have greater control of how information is accessed on the page

    Controller Extension

    If you want to keep most of the functionality of a standard or custom controller it is wiser to have an extension

    controller extension can extend standard or custom controller.

    Thanks.

  • madhulika shah

    Member
    September 19, 2018 at 1:07 pm

    Hi,

    Custom Controller:

    • It is an Apex class that implements all of the logic for a page without leveraging a standard controller.
    • You can use only one Apex class.
    • You can 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.

    Extension:

    • A controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.
    • It provides additional functionality to a controller – either a standard controller or a custom controller.
    • You can use multiple Apex classes separated by comma.
    • 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.

    Thanks.

  • Parul

    Member
    September 23, 2018 at 3:38 am

    Controller extension is very useful and important concept introduced by the salesforce recently. It gives the power to programmer to extend the functionality of existing custom controller or standard controller.
    A Visualforce can have a single Custom controller or standard controller but many controller extensions.
    we can say that the custom extension is the supporter of custom or standard controller.

    If you want to use completely custom functionality and don't really need most of the standard object behaviors, custom controller is a good option, but bear in mind, any standard actions you want to use will have to be implemented in your custom class. A page with a custom controller would use the following attribute:

    <apex:page controller="MyApexClass"...> ... </apex:page>

    Consider one example : If there is one controller written and used by the multiple visualforce pages and one of them needs some extra logic. Then instead of writing that logic to controller class (Which is used by many visualforce pages) we can create a controller extension and apply to that page only.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos