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
Mohit SMohit S 

How to insert new records in custom objects? pls go through the following code

My visualforce page code is as follows

<apex:page sidebar="false" controller="hotelbooking">
    <apex:includeScript value="{URLFOR($$Resources.stylesheet,'stylesheet.css')}"/>
        <apex:form >
          <apex:pageBlock title="Hotel Bookings">
              <apex:tabPanel id="Panel1" width="1000">
                  <apex:tab id="Tab1" label="NEW BOOKING" LabelWidth="300">
                      <table>
                                 <tr>
                                     <td>
                                         BookingDate:
                                     </td>
                                     <td>
                                         <apex:inputtext value="{!bookingdate}"/>
                                     </td>
                                     </tr>
                                     <tr>
                                     <td>
                                         Checkin Time
                                     </td>
                                     <td>
                                         <apex:inputtext value="{!checkin}" />
                                     </td>
                                     </tr>
                                    
                                     <tr>
                                     <td>
                                         CHECKout Time
                                     </td>
                                     <td>
                                         <apex:inputtext value="{!CHECKOUT}"/>
                                     </td>
                                 </tr>
                                   <tr>
                                     <td>
                                         CUSTOMER Name
                                     </td>
                                     <td>
                                         <apex:inputtext value="{!CUSTNAME}"/>
                                     </td>
                                 </tr>
                                   <tr>
                                     <td>
                                         Room TYPE
                                     </td>
                                     <td>
                                         <apex:inputtext value="{!ROOMTYPE}"/>
                                     </td>
                                 </tr>
                                 <tr >
                                     <td colspan="2" align="center">
                                         <apex:commandButton value="INSERT" style="color:red;" 
                                         action="{!doInsert}" />
                                     </td>
                                 </tr>
                             </table>
                   
                  </apex:tab>
                  <apex:tab id="Tab2" label="EDIT BOOKING" LabelWidth="350">
                                <!--apex:column  value="{!b.Booking_ID__c}"/>
                                <apex:column value="{!b.CHECK_IN__c}"/>
                                <apex:column value="{!b.CHECK_OUT__c}"/>
                                <apex:column value="{!b.CUSTOMER_Name__c}"/>
                                <apex:column value="{!b.ROOM__c}"/>-->

                      <apex:pageBlockTable value="{!bookings}" var="b">
                      </apex:pageBlockTable>
                  </apex:tab>
                  <apex:tab id="Tab3" label="VIEW BOOKING" LabelWidth="350">
                      <apex:pageBlockTable value="{!bookings}" var="b">
                                <apex:column value="{!b.Booking_ID__c}"/>
                                <apex:column value="{!b.CHECK_IN__c}"/>
                                <apex:column value="{!b.CHECK_OUT__c}"/>
                                <apex:column value="{!b.CUSTOMER_Name__c}"/>
                                <apex:column value="{!b.ROOM__c}"/>
                      </apex:pageBlockTable>
                  </apex:tab>
              </apex:tabPanel>
          
          </apex:pageBlock>
      </apex:form>
</apex:page>

Controller logic 
public class hotelbooking {

     List<HOTEL_BOOKING__c> Bookings=[select Booking_Date__c,Booking_ID__c,CHECK_IN__c,CHECK_OUT__c,CUSTOMER_Name__c,   ROOM__c
                                      from HOTEL_BOOKING__c ];
 public list<HOTEL_BOOKING__c> getbookings(){
   return bookings;
 }  
 
 public pagereference doinsert(){
   HOTEL_BOOKING__c insrt=new HOTEL_BOOKING__c();
   //insrt.Booking_Date__c=bookingdate;
   insrt.CHECK_IN__c=checkin;
   insrt.CHECK_OUT__c=checkout;
   insrt.CUSTOMER_Name__c  =custname;
   insrt.ROOM__c=roomtype;
   
   insert insrt;
   
   return null;
 }   
 
 public datetime bookingdate  {get;set;} 
 public datetime checkin  {get;set;} 
 public datetime checkout  {get;set;} 
 public string custname  {get;set;} 
 public string roomtype {get;set;}                               
}


Pls help i am unable to insert the records in my custom object Hotel_booking__c.
Waiting for ur good sugetions
THANKS
-MOHIT S
Tarun J.Tarun J.
Hello Mohit,

Did you check debug log? Share it.
Are you getting any error msg?

-Thanks,
TK
Mohit SMohit S
Hello Tarun ,
I know how to debug in C# .net  code but I am new with salesforce environment can u explain how to check debug log ?or how  to debug through this code? 
By the way my above issue is solved by using Standard controller.And now i can insert new records.
Awaiting for the reply..
Tarun J.Tarun J.
Hello Mohit,

Go to Set up, search Debug log in left side search box
User-added image

click on New under 'User Trace Flags' section. Select the user in context and set 'Debug Level' as '
SFDC_DevConsole' and save.

You can view logs under 'Debug Logs' section.

-Thanks,
TK
Mohit SMohit S
Thanks for the Help Tarun!!!
Tarun J.Tarun J.
Kinldy mark it as Solved.