I am trying to build an editable attendance sheet which can record new attendance records and edit old records based on date and course. The user can select a course which then queries the DB for enrolled students and creates a table based on the following APEX in visualforce:
{!Roster}
is my query result on students enrolled in a particular class
{!attendanceOptions}
are the 3 radio options for students attendance, "present," "tardy," and "absent."
<apex:pageBlockTable value="{!Roster}" var="Roster">
<apex:column >
<apex:facet name="header">Student Name</apex:facet>
<apex:outputText value="{!Roster['Name']}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Attendance</apex:facet>
<apex:selectRadio value="{!attendanceRecord}" disabled="{!lockRecords}">
<apex:selectOptions value="{!attendanceOptions}"/>
</apex:selectRadio>
</apex:column>
</apex:pageBlockTable>
I am would like to set the radio buttons value equal to the students' attendance records (present, tardy, or absent) if they exist for a particular day or to "present" is no records exist by changing the {!attendanceRecord}
variable.
Here is the relevant class code for this visualforce page:
public with sharing class TestDisplayQueryList {
public List<String> attendanceRecord {get;set;}
public List<String> getAttendanceRecord(){
if(attendanceRecord == null)
List<String> attendanceRecord = new List<String>();
return null;
}
public List<Contact> getRoster() {
string record;
List<Contact> roster = new List<Contact>();
for(Contact Name : [SELECT Contact.Name, contact.id FROM contact WHERE contact.id IN (SELECT hed__Course_Enrollment__c.hed__Contact__c FROM hed__Course_Enrollment__c WHERE hed__Course_Enrollment__c.hed__Course_Offering__c=:className)]){
roster.add(Name);
for(Course_Attendance__c attendance : [SELECT Attendance_Record__c FROM Course_Attendance__c WHERE Date__c =:dat AND Contact__c =:name.id]){
record = attendance.Attendance_Record__c;
record = record.toLowerCase();
attendanceRecord.add(record);
roster.add(new string attendanceRecord);
}
}
}
The problem is that I keep getting the error "Attempt to de-reference a null object" referencing the attendanceRecord.add(record);
line of code as if the variable attendanceRecord
doesn't exist. What am I doing wrong that is preventing this public variable from being used in this function?