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 

In my visualForce page i write custom controller and i get error: Unknown property 'HospitalController.Doc'

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 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)); 
        }
    }
    }
and visualforce page 
<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">
<apex:selectOptions value="{!patientSelectOptionList}"/>
</apex:selectList>
</apex:pageBlockSection>
    

<apex:pageBlock>

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

</apex:pageBlock>






    
   
    
    <apex:pageBlockSection >
<apex:commandButton immediate="false" reRender="app_list3" action="{!addNewAppt}" value="Add New Appointment" />
</apex:pageBlockSection>
    
    <!-- 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>
    
    
<!-- 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>


 
Omar Rajab 94Omar Rajab 94
Hi Sirhaei,
in the visualforce page you are trying to iterate the variable "doc" which is not declared in the apex controller, you should use doctorList instead of!

try below the edited code for the Visualforce page:
<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">
<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>






    
   
    
    <apex:pageBlockSection >
<apex:commandButton immediate="false" reRender="app_list3" action="{!addNewAppt}" value="Add New Appointment" />
</apex:pageBlockSection>
    
    <!-- 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>
    
    
<!-- 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>

 

Regards,
Omar

Siarhei balantsevichSiarhei balantsevich
i have this error
SObject row was retrieved via SOQL without querying the requested field: Doctor__c.working_hours_start__c
 
Omar Rajab 94Omar Rajab 94
I think the apex controller is chnaged. Please send me the latest version!

 
Siarhei balantsevichSiarhei balantsevich
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 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)); 
        }
    }
    }

 
Omar Rajab 94Omar Rajab 94
I stil can not see why you get this error.
all the soql in the controller have the field "working_hours_start__c". Could you send the whole stack trace?


 
Siarhei balantsevichSiarhei balantsevich
wher i find stack trace. I new in salesforce
 
Omar Rajab 94Omar Rajab 94
If you run the Visualforce page at the same time you open the Developer console, then a log will be created in logs tab in the Developer console.
Siarhei balantsevichSiarhei balantsevich
User-added image
Siarhei balantsevichSiarhei balantsevich
User-added image
Omar Rajab 94Omar Rajab 94
Now scroll down untill you find the exception messgae
Siarhei balantsevichSiarhei balantsevich
20:35:15:048 EXCEPTION_THROWN [EXTERNAL]|System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Doctor__c.working_hours_start__c
Omar Rajab 94Omar Rajab 94

Sorry but it did not tell me anything. 

I want to see in which line exactly is the code failed.
send me the Visualforce page again?

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

 
Omar Rajab 94Omar Rajab 94
Last attempt, recompile the controller.
Siarhei balantsevichSiarhei balantsevich
don't work
Omar Rajab 94Omar Rajab 94
Sorry i want to help but some Informations are missed :(