+ Start a Discussion
Siarhei balantsevichSiarhei balantsevich 

how to write a new object of class appointment__c with input fields

public class HospitalController {
 public Appointment__c appt {get; set;}
    public List<Doctor__c>  doclists{set;get;}
    public String selectedDoctor {get; set;}
    public String selectedPatient {get; set;}
    public Datetime appDate {get; set;}
    public List<Doctor__c> DoctorList {get;set;}
    public List<SelectOption> doctorSelectOptionList {get;set;}
    public List<Patient__c> PatientList {get;set;}
    public List<SelectOption> patientSelectOptionList {get;set;} 
    public Integer duration {get; set;}
    public List<appointment__c> tableAppointments{get; set;}
    public Time TimeStart {get;set;}
 //   public PageReference addNewAppt() {
 //    return null;
    public Integer PageNumber {get; set;}
    Public Integer PageSize {get;set;}
    Public Integer ResultSize {get;set;} 
     public PageReference addNewAppt() {
            this.appt.Doctor__c = selectedDoctor;
            this.appt.Patient__c = selectedPatient;
            //Duration and Appointment Date will be populated by VF page
            insert this.appt;

     public list<Doctor__c> getDoc()
       return [Select working_hours_start__c From Doctor__c];
    public PageReference redirectToMyVF(Id accId) { 
    PageReference myVFPage = new PageReference('/apex/myVFPage');
    myVFPage.getParameters().put('myId', accId);
    return myVFPage;
    public HospitalController() {
        this.appt = new Appointment__c();
        this.selectedDoctor = '';
        this.selectedPatient = '';
        this.appDate = System.now();
        this.duration = 30;
        doctorSelectOptionList = new List<SelectOption>();
        patientSelectOptionList = new List<SelectOption>();
        DoctorList = [SELECT iD, Name,working_hours_start__c FROM Doctor__c];
        //TimeStart = DoctorList.working_hours_start__c;
        for (Doctor__c doc : DoctorList){ 
            doctorSelectOptionList.add(new SelectOption(doc.Id, doc.Name)); 
        PatientList = [SELECT Id, Name FROM Patient__c];
        for (Patient__c patient : PatientList){
            patientSelectOptionList.add(new SelectOption(patient.Id, patient.Name)); 
i trying this function public PageReference addNewAppt() but id doesen't work.

visual force 
<apex:page docType="html-5.0" controller="HospitalController" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock title="Appointmets Table">

<!-- Select a doctor -->
 Select a doctor:
<apex:selectList size="1" value="{!selectedDoctor}">
<apex:selectOptions value="{!doctorSelectOptionList}"/>
<apex:actionSupport event="onchange" 
reRender="app_list1, app_list2, app_list3"/>

<!-- Select a patient -->
Select a patient:
<apex:selectList size="1" value="{!selectedPatient}">
<apex:selectOptions value="{!patientSelectOptionList}"/>

  <apex:pageBlockTable value="{!doctorList}" var="item">
       <apex:column value="{!item.working_hours_start__c}"/>


    <!-- Appointment date -->
<apex:pageBlockSection >
<apex:inputField label="Appointment date" 
     <apex:pageBlockSection >
                <apex:inputField label="Duration in minutes" 
    <apex:pageBlockSection >
<apex:commandButton immediate="false" reRender="app_list3" action="{!addNewAppt}" value="Add New Appointment" />
<!-- Pagination -->
<table style="width: 100%"><tr>
Page: <apex:outputText 
value="{!PageNumber} of {!CEILING(ResultSize / PageSize)}"/>
<td align="center">
<!-- Previous page -->
<!-- active -->

<!-- Next page -->
<!-- active -->

<td align="right">
<!-- Records per page -->
Records per page:
<apex:selectList value="{!PageSize}" size="1">
<apex:selectOption itemValue="5" itemLabel="5"/>
<apex:selectOption itemValue="20" itemLabel="20"/>
<apex:actionSupport event="onchange" reRender="contacts_list"/>
Siarhei balantsevichSiarhei balantsevich
User-added image