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
KPDKPD 

VF page creation

Hello all.
Can someone help me in creating the visualforce page for following requirement:

Page should take input from user first name , last name .
User should be able to click on create contact button.As soon as user clicks on the create contact button, a contact in system should get created and show the salesforce id of the contact created on visualforce.
Apoorv Saxena 4Apoorv Saxena 4
Hi,

Please try the below code :

Visualforce Page :
 
<apex:page StandardController="Contact" extensions="createContactExt">
<apex:form >
    
    <apex:pageBlock >
        <apex:pageblockButtons >
            <apex:commandButton value="Create Contact" action="{!createContact}"/>
        </apex:pageblockButtons>
        <apex:pageBlockSection >
            <apex:inputField value="{!con.firstname}"/>
            <apex:inputField value="{!con.lastname}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
  
</apex:page>

Apex Extension Class :
 
public class createContactExt {

public Contact con{get;set;}

    public createContactExt(ApexPages.StandardController controller) {
        con = new Contact();
    }
    
    public pageReference createContact(){
        
        insert con;
        Pagereference pr = New PageReference('/' + con.id);
        return pr; 
    }

}

Please mark this as solved if this helps you !

Thanks,
Apoorv