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 to make it so that when you select a value in the doctor field, the table is redrawn only with the values of the selected doctor

Apex code
 
public with sharing 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 List<Appointment__c> appList {get;set;} 
    public string str_1 {get;set;}
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
    
    public app_test_1(){
        
        SelectreDdoc();
        
        str_1='gmak';
     
        appt=new Appointment__c();
     //   getApp();
         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)); 
        }
        
         size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
        
    }
    
    
public PageReference save() {
return null;
}

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

   
    appt.clear();
    
PageReference pr = new PageReference('/apex/vs_g_t_01');
   pr.setRedirect(true);
   return pr;
}
    
    
    
       public list<Doctor__c> getDoc()
    {
       return [Select Name, working_hours_start__c,Working_Hours_End__c From Doctor__c
              where Name Like :selectedDoctor];
           
    }

    
    
     public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select ID,NAme,Doctor__r.Name,patient__r.Name,Duration_in_minutes__c	,Appointment_Data__c	FROM Appointment__c  ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Appointment__c> getApp() {
         return (List<Appointment__c>) setCon.getRecords();
    }
    
  public PageReference SelectreDdoc() {
         selectedDoctor =this.selectedDoctor;
         return null;
    }
    
    
  public PageReference SelectrePatient() {
         selectedPatient =this.selectedPatient;
         return null;
    }
    
    public PageReference RedirDoctor(){
        PageReference pr = new PageReference('/lightning/o/Doctor__c/home');
   pr.setRedirect(true);
   return pr;
    }
    public PageReference RedirPatient(){
        PageReference pr = new PageReference('/lightning/o/Patient__c/home');
   pr.setRedirect(true);
   return pr;
    }
}

Visualforce
 
<apex:page controller="app_test_1">
    
    <apex:form >
        
<apex:pageBlock title="appointment">
    
    <!-- Select a doctor 
<apex:pageBlockSection >
 Select a doctor:
<apex:selectList size="1" multiselect="false" value="{!selectedDoctor}" onchange="SelectreDdoc();">
<apex:selectOptions value="{!doctorSelectOptionList}"/>
     <apex:actionSupport event="onchange" reRender="selected"/>

</apex:selectList>
</apex:pageBlockSection>
    
-->    
 
    
    
    
    
    
<apex:pageBlock >	

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

      <apex:pageBlockSection >
       Select a doctor:
<apex:outputPanel id="selectedDoctor">{!selectedDoctor}</apex:outputPanel>

    <apex:selectList size="1" value="{!selectedDoctor}">
        <apex:selectOptions value="{!doctorSelectOptionList}"/>
        <apex:actionSupport event="onchange" reRender="selected"/>
    </apex:selectList>

    
    
</apex:pageBlockSection>
    
    
<!-- Select a patient -->
<apex:pageBlockSection >
Select a patient:
<apex:selectList size="1" multiselect="false" value="{!selectedPatient}" onchange="SelectrePatient();">
<apex:selectOptions value="{!patientSelectOptionList}"/>
</apex:selectList>
    
    
    
    
    
    
</apex:pageBlockSection>
    
    
    
     <apex:pageBlockSection >
                <apex:inputField label="Duration in minutes" 
                            value="{!appt.Duration_in_minutes__c}"
                            required="false"/>
            </apex:pageBlockSection>
    
    
    <!-- Appointment date -->
<apex:pageBlockSection >
<apex:inputField label="Appointment date" 
                 value="{!appt.Appointment_Data__c}"
required="false"/>
</apex:pageBlockSection>
   
          <apex:pageBlockButtons >
  
    <apex:commandButton reRender="pbId" value="Add new appointment" action="{!saveandnew}" />
              <apex:commandButton reRender="pbId" value="Add new doctor" action="{!RedirDoctor}" />
              <apex:commandButton reRender="pbId" value="Add new Patient" action="{!RedirPatient}" />
    </apex:pageBlockButtons>
        
        
        </apex:pageBlock>
        <script type="text/javascript">
console.log('{!selectedDoctor}');
</script>  
    
          <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/>
        <apex:pageBlock id="pbId">
            <apex:pageBlockSection title="All Opportunities" collapsible="false" columns="1">
                <apex:pageBlockTable value="{!App}" var="oppObj">
                     
                    <apex:column headerValue="Action">
<apex:outputLink value="{!URLFOR('/' + oppObj.Id)}">
View
</apex:outputLink>
                      </apex:column>
                    <apex:column headerValue="Doctor Name">
                        <apex:outputField value="{!oppObj.Doctor__r.Name}"/>
                    </apex:column>
                     
                    <apex:column headerValue="Patient Name">
                        <apex:outputField value="{!oppObj.patient__r.Name}"/>
                    </apex:column>
                     
                    
                     
                    <apex:column headerValue="Appointment Data">
                        <apex:outputField value="{!oppObj.Appointment_Data__c}"/>
                    </apex:column>
                    <apex:column headerValue="Appointment Duration">
                        <apex:outputField value="{!oppObj.Duration_in_minutes__c}"/>
                    </apex:column>
                    
                </apex:pageBlockTable>
                 
                <apex:panelGrid columns="8"> 
                 
                <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                    <apex:selectOptions value="{!paginationSizeOptions}"/>
                </apex:selectList>
                 
                <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> 
  
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,
                     (setCon.pageNumber * size))} of {!noOfRecords}
                </apex:outputText> 
                       
                <apex:outputPanel >                      
                    <apex:actionStatus id="fetchStatus" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel> 
  
            </apex:panelGrid>  
            </apex:pageBlockSection>
        </apex:pageBlock>
        
    
    </apex:form>
    </apex:page>

 
SwethaSwetha (Salesforce Developers) 
HI Siarhei balantsevich,
Your ask is specific to your custom implementation and so it would be difficult to provide an exact edit suggestion.
The example on https://sfdcmonkey.com/2016/12/05/how-to-fetch-picklist-value-from-sobject-and-set-in-uiinputselect/ should help you get started.

The Developer community can suggest better if you share a simplified code snippet stating what you are trying to accomplish and where you are stuck.

If this information helps, please mark the answer as best. Thank you