You need to sign in to do that
Don't have an account?
Siarhei balantsevich
how to write a new object of class appointment__c with input fields
controller
visual force
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.setRedirect(true); 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 --> <apex:pageBlockSection> Select a doctor: <apex:selectList size="1" value="{!selectedDoctor}"> <apex:selectOptions value="{!doctorSelectOptionList}"/> <apex:actionSupport event="onchange" reRender="app_list1, app_list2, app_list3"/> </apex:selectList> </apex:pageBlockSection> <!-- Select a patient --> <apex:pageBlockSection> Select a patient: <apex:selectList size="1" value="{!selectedPatient}"> <apex:selectOptions value="{!patientSelectOptionList}"/> </apex:selectList> </apex:pageBlockSection> <!-- <apex:pageBlock> <apex:pageBlockTable value="{!doctorList}" var="item"> <apex:column value="{!item.working_hours_start__c}"/> </apex:pageBlockTable> </apex:pageBlock> --> <!-- Appointment date --> <apex:pageBlockSection > <apex:inputField label="Appointment date" value="{!appt.Appointment_Data__c}" required="false"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:inputField label="Duration in minutes" value="{!appt.Duration_in_minutes__c}" required="false"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:commandButton immediate="false" reRender="app_list3" action="{!addNewAppt}" value="Add New Appointment" /> </apex:pageBlockSection> <!-- Pagination --> <table style="width: 100%"><tr> <td> Page: <apex:outputText value="{!PageNumber} of {!CEILING(ResultSize / PageSize)}"/> </td> <td align="center"> <!-- Previous page --> <!-- active --> <!-- Next page --> <!-- active --> </td> <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"/> </apex:selectList> </td> </tr></table> </apex:pageBlock> </apex:form> </apex:page>
Siarhei balantsevich