Introduction to Standard Controller
Visualforce consists of many built-in controllers like Standard controller, Custom controller or extension controller based on the need, which can be used to access and display data.
It based on the MVC (model-view-controller) approach. The controllers (Apex classes) interact with the Salesforce database(model) and pull the data from the salesforce database to view(visualforce) the data through a webpage created by page.
Standard Controller: we use standard controller whenever we want to connect our Visualforce page with any sObject(Standard/Custom)
Creating Input Form using Standard Controller:
Let us create Input form(where user will fill the value and then save the page) using standard controller in visualforce page. We write the code as shown below which uses Account as the standard controller and the purpose is to create the values in the 3 fields – Account Name, Phone and Fax.
<apex:page standardController="Account"> <apex:form > <apex:pageblock title="Account Edit"> <apex:pageblockSection columns="3" title="Account"> <apex:inputfield value="{!Account.name}"/> <apex:inputfield value="{!Account.phone}" required="true"/> <apex:inputfield value="{!Account.fax}"/> </apex:pageblockSection> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> </apex:pageblock> </apex:form> </apex:page>
On clicking on preview the page, we get the following output.
Note: Now, it’s completely functional page here you can fill the Account Name, Phone and Fax then click on Save button your data will be saved in Salesforce Account Object.