+ Start a Discussion
Ian Lin 20Ian Lin 20 

how to create a page with fields in salesforce using visualforce pages??

Deepali KulshresthaDeepali Kulshrestha
Hi Ian,

Please check the below sample code.
Visualforce page:
<apex:page Controller="ContactController" >
    <apex:form >
        <apex:pageBlock title="Edit Contact">

            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!c.FirstName}"/>
                <apex:inputField value="{!c.LastName}"/>
                <apex:inputField value="{!c.Email}"/>
                <apex:inputField value="{!c.Birthdate}"/>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
          <apex:pageBlockTable value="{!samepage}" var="c">
          <apex:column headerValue="First Name">
          <apex:outputField value="{!c.Firstname}"/>
          <apex:column headerValue="Last Name">
          <apex:outputField value="{!c.Lastname}"/>
          <apex:column headerValue="Birthdate">
          <apex:outputField value="{!c.Birthdate}"/>


public with sharing class ContactController {

    public Contact c { get; set; }

    public List<Contact> samepage { get; set; }
    public ContactController(){
       c=new Contact();

    public PageReference save() {
       insert c;  
      samepage= [select id,FirstName,LastName,Email,Birthdate from Contact where id=:c.id];
        return null;


The <apex:inputField> component respects the attributes of the associated field, including whether the field is required or unique, and the user interface widget to display to get input from the user. For example, if the specified <apex:inputField> component is a date field, a calendar input widget is displayed. 

I suggest to visit this link, it will help you


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.