Didn't get any error but data isn't getting saved in contact and reservation object after clicking the save button...
I am having two object reservation and contact are in look-up relation. I want to insert the page details as attached in the image in their respective objects with a particular contact record and particular Reservation record created after save button clicked from VF page. VF page contain following fields: FirstName LastName Phone (Contact object) Booking Time/Date(Required field in Reservation field) Customer_Name__c (as Look-up)
Controller:
public class CustomController{
public Contact contact {get; set;}
public Reservation__c reservation {get; set;}
public void CustomController(){
contact = new Contact();
reservation = new Reservation__c();
}
public void save(){
try{
insert contact;
reservation.Customer_Name__c = contact.Id;
insert reservation;
}
catch(Exception e){
/** Handle exception **/
}
}
}
VisualForce Page:
<apex:page Controller="CustomController" >
<apex:sectionHeader title="Reservation"/>
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="Welcome To ForkWork">
<apex:pageBlockSection columns="1" >
<apex:inputField value="{!contact.salutation}" />
<apex:inputField value="{!contact.firstname}" />
<apex:inputField value="{!contact.lastname}" />
<apex:inputField value="{!contact.phone}" />
</apex:pageBlockSection>
<apex:pageBlockSection columns="2" >
<apex:inputField value="{!reservation.Booking_Time_Date__c}" required="true"/>
<apex:inputField value="{!reservation.Table_for__c}" />
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>