• Pavel Bandarenka
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Controller:public class AppointmentsViewController {


    public List<Doctor__c> doctorList {get;set;}
    public List<SelectOption> doctorSelectOptionList{get;set;}
    public List<Appointment__c> apointmentList{get;set;}
    public String doctorId {get;set;}
    public List<Patient__c> patientList{get;set;}
    public List<SelectOption> patientSelectOptionList{get;set;}
    public Integer noOfRecords{get; set;}
    public Integer size{get;set;}
    
    public AppointmentsViewController() {
       doctorList = [
           SELECT Id, Name, Working_Hours_Start__c, Working_Hours_End__c
           FROM Doctor__c
           ORDER BY Name ASC
       ];
        
        patientList = [
            SELECT Id, Name
            FROM Patient__c
        ];
        
        patientSelectOptionList = new List<SelectOption>();
        
        for(Patient__c item :patientList)
        {
            patientSelectOptionList.add(new SelectOption(item.Id, item.Name));
        }
        doctorId = doctorList.isEmpty() == FALSE ? doctorList[0].Id : NULL;
        
       doctorSelectOptionList = new List<SelectOption>();
        
        for(Doctor__c item :doctorList) {
            doctorSelectOptionList.add(new SelectOption(item.Id, item.Name));
        }
        getAppointments();
       
        
    }
    
    public void getAppointments () {
        apointmentList = [
            SELECT Id, Name, Doctor__c, Patient__c, Appointment_Date__c, Duration_in_minutes__c
            FROM Appointment__c
            WHERE Doctor__r.Id = :doctorId
        ];
    }



    public List<Appointment__c> Appointment { get{

        return (List<Appointment__c>)setCon.getRecords();

    } set; }



    public ApexPages.StandardSetController setCon {

        get{

            if(setCon == null){

                size = 20;

                List<Appointment__c> Appointment = [
                    SELECT Id, Name, Doctor__c, Patient__c, Appointment_Date__c, Duration_in_minutes__c
                    FROM Appointment__c];

                setCon = new ApexPages.StandardSetController(Appointment);

                setCon.setPageSize(size);

                noOfRecords = setCon.getResultSize();

            }

            return setCon;

        }set;

    }






}




Test:
@isTest
private class AppointmentsViewControllerTest {
    
    @isTest static void AppointmentsViewControllerTest1() {
        
        Doctor__c doctor = new Doctor__c(
        );
        
        insert doctor;
        
        AppointmentsViewController controller = new AppointmentsViewController();
        
        Appointment__c Appointment = new Appointment__c(
        );
        insert Appointment;
        
            ApexPages.standardSetController sc = new ApexPages.standardSetController(doctor

        
        
     // ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController(doctor);
        
    }
    
       
    

}
Controller:public class AppointmentsViewController {


    public List<Doctor__c> doctorList {get;set;}
    public List<SelectOption> doctorSelectOptionList{get;set;}
    public List<Appointment__c> apointmentList{get;set;}
    public String doctorId {get;set;}
    public List<Patient__c> patientList{get;set;}
    public List<SelectOption> patientSelectOptionList{get;set;}
    public Integer noOfRecords{get; set;}
    public Integer size{get;set;}
    
    public AppointmentsViewController() {
       doctorList = [
           SELECT Id, Name, Working_Hours_Start__c, Working_Hours_End__c
           FROM Doctor__c
           ORDER BY Name ASC
       ];
        
        patientList = [
            SELECT Id, Name
            FROM Patient__c
        ];
        
        patientSelectOptionList = new List<SelectOption>();
        
        for(Patient__c item :patientList)
        {
            patientSelectOptionList.add(new SelectOption(item.Id, item.Name));
        }
        doctorId = doctorList.isEmpty() == FALSE ? doctorList[0].Id : NULL;
        
       doctorSelectOptionList = new List<SelectOption>();
        
        for(Doctor__c item :doctorList) {
            doctorSelectOptionList.add(new SelectOption(item.Id, item.Name));
        }
        getAppointments();
       
        
    }
    
    public void getAppointments () {
        apointmentList = [
            SELECT Id, Name, Doctor__c, Patient__c, Appointment_Date__c, Duration_in_minutes__c
            FROM Appointment__c
            WHERE Doctor__r.Id = :doctorId
        ];
    }



    public List<Appointment__c> Appointment { get{

        return (List<Appointment__c>)setCon.getRecords();

    } set; }



    public ApexPages.StandardSetController setCon {

        get{

            if(setCon == null){

                size = 20;

                List<Appointment__c> Appointment = [
                    SELECT Id, Name, Doctor__c, Patient__c, Appointment_Date__c, Duration_in_minutes__c
                    FROM Appointment__c];

                setCon = new ApexPages.StandardSetController(Appointment);

                setCon.setPageSize(size);

                noOfRecords = setCon.getResultSize();

            }

            return setCon;

        }set;

    }






}




Test:
@isTest
private class AppointmentsViewControllerTest {
    
    @isTest static void AppointmentsViewControllerTest1() {
        
        Doctor__c doctor = new Doctor__c(
        );
        
        insert doctor;
        
        AppointmentsViewController controller = new AppointmentsViewController();
        
        Appointment__c Appointment = new Appointment__c(
        );
        insert Appointment;
        
            ApexPages.standardSetController sc = new ApexPages.standardSetController(doctor

        
        
     // ApexPages.StandardSetController standardSetController = new ApexPages.StandardSetController(doctor);
        
    }
    
       
    

}