• #30551

    Can anyone compare and contrast custom controllers & controller extensions in Salesforce?

    Compare And Contrast Custom Controllers And Controller Extensions.



    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.




    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.


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


    Salesforce | Parul Parul #2

    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.

Viewing 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?