Activity › Forums › Salesforce® Discussions › Can any one tell me when do we use custom controller in Salesforce with extension class?
Tagged: Custom Controller, MVC, Salesforce Controller, Salesforce Customization, Salesforce Extension Class, Salesforce Extensions, Standard Controller
-
Can any one tell me when do we use custom controller in Salesforce with extension class?
Posted by Uday on August 17, 2017 at 4:34 PMAny one tell me when we use custom controller with extension class.Please give me one example
Avnish Yadav replied 7 years, 7 months ago 3 Members · 2 Replies -
2 Replies
-
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 componentsNow 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..!!!
- [adinserter block='9']
-
Hello,
When using custom controller you may or may not create constructor as a default constructor is always present when you ceate any class.
Thanks.
Log In to reply.