function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
          <apex:pageBlockTable value="{!samepage}" var="c">
          <apex:column headerValue="First Name">
          <apex:outputField value="{!c.Firstname}"/>
          </apex:column>
          
          <apex:column headerValue="Last Name">
          <apex:outputField value="{!c.Lastname}"/>
          </apex:column>
          
          <apex:column headerValue="Birthdate">
          <apex:outputField value="{!c.Birthdate}"/>
          </apex:column>
          </apex:pageBlockTable>
        </apex:pageBlock>
        
    </apex:form>
</apex:page>

Controller

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

https://trailhead.salesforce.com/en/content/learn/modules/visualforce_fundamentals

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.