- August 17, 2017 at 4:34 pm #21720Uday #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 exampleAugust 21, 2017 at 3:31 am #21736Radhakrishna #29
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 Visualforce page
From Developer console
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.
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.
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..!!!September 30, 2018 at 5:34 am #41481
Please Register to reply to this topic. /