Visualforce Controllers : In our previous Salesforce Tutorial we have learned about how to create new visualforce page. In this Salesforce Training Tutorial we are going to learn about different Visualforce Controllers used in force.com development.
Before going to study about visualforce controllers in force.com development we have to know about what is meant by controller? How a controller is used in visualforce pages and what are the different types of visualforce controllers.
What is meant by a Visualforce Controller?
Visualforce controller is the second type element in Visualforce pages which has set of instructions to manipulate data and schema with user interactions.
How a Controller is used in Visualforce pages ?
- Controllers are those who provide business logic to Visualforce pages.
- It accepts data from user like input values.
- Controller manipulates user’s input and performs action on behalf of the User.
- Manipulated User’s data is redirected to browser as a new page.
What are the different types of Visualforce Controllers?
When coming to visualforce controllers in force.com development there are three types of controllers. They are
- Standard Controllers.
- Custom Controllers.
- Controller extensions.
Standard Controllers :- Standard controllers are the default Controller’s provided by Force.com. These standard controllers will have same logic and functionality used standard visualforce pages. No Apex code is required in Standard Controllers
Syntax :- <apex:page standardcontroller =”contact”></apex:page>
Custom controller :- When a developer needs different logic and functionality he/she may write their own Apex controller class. Custom controller’s will not provide default functions like standard controllers. Custom apex code must be written for custom controllers.
Syntax :- <apex : page controller = “Mycontroller”></apex:page>
Extension controllers :-If we want to use both custom controller functionality and standard controller functionality we use extension controllers. Extension Controllers begins with Standard controller and extended or overridden with custom controller with custom apex code.
Syntax :- <apex:page standardcontroller = “contact” extensions = “Testclass1, Testclass2?></apex:page>