Using the Visualforce apex:form component, create a page which will insert a Contact record based on First Name, Last Name and Email. After submitting the form, the user should be redirected to detail page of the new Contact record.
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;
}
}
I hope it will be helpful.
Please mark it as best Answer if the information is informative.
Please check the below sample code.
Visualforce Page:
Controller:
I hope it will be helpful.
Please mark it as best Answer if the information is informative.
Best Regards
Rahul Kumar
<apex:page standardController="Contact" Sidebar="False">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{! Contact.FirstName }"/>
<apex:inputField value="{! Contact.LastName}"/>
<apex:inputField value="{! Contact.Email }"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{! save }" value="Save" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
i checked my whole contact
<apex:form>
<apex:pageBlock title="Contact Info">
<apex:pageBlockSection>
<apex:inputField value="{! Contact.FirstName }"/>
<apex:inputField value="{! Contact.LastName }"/>
<apex:inputField value="{! Contact.Email }"/>
<apex:commandButton action="{! save }" value="Save" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>