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
Siarhei balantsevichSiarhei balantsevich 

how i can get selected id in selectlist

how i can get selected id in selectlist? I need to save a new object based on this value
 
<apex:pageBlockSection >
 Select a doctor:
<apex:selectList size="1" value="{!selectedDoctor}">
<apex:selectOptions value="{!doctorSelectOptionList}"/>
<apex:actionSupport event="onchange" action="console.log('{!selectedPatient}')"
reRender="app_list1, app_list2, app_list3"/>
</apex:selectList>
</apex:pageBlockSection>

value don't help me
ANUTEJANUTEJ (Salesforce Developers) 
Hi Siarhei,

You need to have getter and setter methods in the controller class to get the selected option. You can check the below implementations in the below links:

>> https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm
>> https://developer.salesforce.com/forums/?id=9060G0000005S9CQAU

Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.  

Thanks.
Siarhei balantsevichSiarhei balantsevich
what class i need write get;set??
public class app_test_1 {

 public Appointment__c appt {get; set;}
    public string Doc_name {get;set;}
    public string Patient_name {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 app_test_1(){
       
        Patient_name = 'a015g00000KIFvGAAX';
        appt=new Appointment__c();
        
         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)); 
        }
    }
    
    
public PageReference save() {
return null;
}

public PageReference saveandnew() {
     Doc_name = selectedDoctor;
    appt.Doctor__c=selectedDoctor;
    appt.patient__c=Patient_name;
insert appt;

PageReference PageRef = new PageReference('/apex/vs_g_t_01');
appt.clear();
return PageRef;
}
}