• #21720
    Salesforce | Uday Uday #599

    Can any one tell me when do we use custom controller in Salesforce with extension class?

    Any one tell me when we use custom controller with extension class.Please give me one example



    Hello Uday,

    Hope you will have better understanding now with these many answers… 🙂

    Let me add few more points here, I would say, A Controller is an Apex Class but an Apex Class is not always a Controller. Further you can call apex class in many different ways:-

    From another class
    From Trigger
    From Visualforce page
    From Developer console
    Form JavaScript button, Links
    From Home page components

    Now if we talk about Controller:-
    In MVC, the view (the Visualforce page) interacts with a controller, and the controller provides functionality to the page. For example, the controller can contain the logic to be executed when a button is clicked. A controller also typically interacts with the model (the database)—making available data that the view might want to display, or pushing changes back to the database.

    Standard Controller:-
    Most standard and all custom objects have standard controllers that can be used to interact with the data associated with the object, so you don’t need to write the code for the controller yourself. You can extend the standard controllers to add new functionality, or create custom controllers from scratch.

    Custom controller:-
    When you want to override existing functionality, customize the navigation through an application, use callouts or Web services, or if you need finer control for how information is accessed for your page, Visualforce lets you take the reigns. You can write a custom controller using Apex and completely control your app’s logic from start to finish.

    Now I will give you a simple scenario:-
    Suppose you have been asked to display the list of all Account on a visual force page then you will definitely start with Standard controller and using pageBlock table you can simply display all accounts. Now if I say to display list of account having Industry = “Agriculture” and Type = “Customer – Channel”, then you have to think about custom controller where you write SOQL with some filter on Account.

    So, you have a better control over the page now as you are writing the code (a custom controller) that will fetch the data based on your requirement.

    Hope this will help you..!!!



    When using custom controller you may or may not create constructor as a default constructor is always present when you ceate any class.

Viewing 3 posts - 1 through 3 (of 3 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?