1

I am using visual force to show the parent and child at a single table. Now I want to make a child column editable. When I click on Class Notes Only the first row is editable but another row is not editable and the saves method is not working correctly.

<apex:page sidebar="false" controller="StudentListView" id="thePage" showHeader="true">
    <apex:form >
    <apex:pageBlock >
    <apex:pageBlockTable value="{!scheduleClasses}" var="parent" id="theTable">
        <apex:column value="{!parent.Instructor__r.Name}" />
        <apex:column value="{!parent.Start_Date__c}" />
        <apex:column value="{!parent.End_Date__c}" />
        <apex:column value="{!parent.Duration_In_Hour__c}" />
        <apex:column headerValue="Topic">
            <apex:outputText value="{!parent.Class_Track_Name__r.Name}" />
        </apex:column>
        <apex:column value="{!parent.Note__c}" />
        
        <apex:column >
            <apex:pageBlockTable value="{!classAttendanceList}" var="attendance">
                <apex:column headerValue="Student Name">
                    <apex:outputText value="{!attendance.Student__r.Name}" />
                </apex:column>
                <apex:column headerValue="Time/Day of the session">
                    <apex:outputText value="{0,date,MM/dd/yy}"> 
                        <apex:param value="{!attendance.Class_Start_Date__c}" />
                    </apex:outputText>
                    <apex:outputText value=" - " />
                    <apex:outputText value="{!attendance.Class_Start_Time__c}" />
                </apex:column>
                <apex:inlineEditSupport showOnEdit="saveButton" hideOnEdit="editButton" event="ondblclick"/>
                <apex:column value="{!attendance.Class_Notes__c}" />
            </apex:pageBlockTable>
        </apex:column>
    </apex:pageBlockTable>
        <apex:pageBlockButtons > 
        <apex:commandButton value="Edit" action="{!save}" id="editButton" />
        <apex:commandButton value="Save" action="{!save}" id="saveButton" />
    </apex:pageBlockButtons> 
    </apex:pageBlock>
    </apex:form>
</apex:page>

public with sharing class StudentListView {
    List<Scheduled_Class__c> scheduleClasses {get; set;}
    List<Attendance__c> classAttendanceList {get; set;}

    public String currentRecordId {get;set;}

    public List<Scheduled_Class__c> getScheduleClasses() {
        currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
        if (scheduleClasses == null) {
            scheduleClasses = [SELECT Id, Instructor__r.Name, Note__c, Duration__c, FORMAT(Start_Date__c), FORMAT(Start_Time__c), End_Date__c, End_Time__c, Duration_In_Hour__c, Class_Track_Name__r.Name, (SELECT Id, Student_Name__c, Student_Status__c, Course_Status__c FROM Class_Attendances__r) FROM Scheduled_Class__c WHERE Id = :currentRecordId];
        }
        return scheduleClasses;
    }

    public List<Attendance__c> getClassAttendanceList() {
        if (classAttendanceList == null) {
            currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
            classAttendanceList = [SELECT Id, Instructor_Name__c, Student_Name__c, Class_Notes__c, FORMAT(Class_End_Date__c), FORMAT(Class_Start_Date__c), Class_Start_Time__c, Student__r.Name, Class_End_Time__c FROM Attendance__c WHERE Scheduled_Class__r.Id = :currentRecordId];
        }
        return classAttendanceList;
    }
    public Pagereference save() {
        try{
            update classAttendanceList;
            return ApexPages.CurrentPage();
        }
        catch(Exception e){
            System.debug(e.getMessage());
            return null;
        }
    }
}
New contributor
Abu Sayem is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

Your Answer

Abu Sayem is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.