Activity Forums Salesforce® Discussions How to get child object records by check the checkbox of parent record

  • How to get child object records by check the checkbox of parent record

    Posted by SANJAY on April 21, 2017 at 5:48 pm

    Hello everyone I am new to salesforce. Strucked in one task please help me. My task is to get related student reports(Child object) by clicking the checkbox of student name(parent object). My code is given below:
    VFpage:

    <apex:page controller="SelCheckBox_cntrl" sidebar="false">
    <apex:form >
    <apex:pageBlock title="Select Student Name">
    <apex:SelectCheckboxes value="{!coolbool}">
    <apex:SelectOptions value="{!StudentNames}"/>
    <apex:actionSupport event="onclick" reRender="messagebox"/>
    </apex:SelectCheckboxes>
    </apex:pageBlock>
    <apex:pageBlock title="Related Selected Reports">
    <apex:pageBlockTable value="{!srep}" var="SR">
    <apex:column value="{!SR.Name}"/>
    </apex:pageBlockTable>
    </apex:pageBlock>
    <apex:commandButton value="Get Selected Reports" action="{!selctedReports}"/>
    </apex:form>
    </apex:page>

    APEX Code:

    public class SelCheckBox_cntrl {
    public String StudentDetails{set;get;}
    public List<Student_Reports__c> srep{set;get;}
    public Boolean coolbool{set;get;}

    public SelCheckBox_cntrl(){
    srep = new List<Student_Reports__c>();
    coolbool = false;
    }

    public List<SelectOption> getStudentNames(){
    List<SelectOption> Sel = new List<SelectOption>();
    for(Student_Details__c SD : [Select id,Name from Student_Details__c]){
    Sel.add(new SelectOption(SD.id,SD.Name));
    }
    return Sel;
    }

    public void selctedReports(){
    if(coolbool==true){
    srep = [Select id,Name,Student_Name__c,Test1__c,Test2__c,Test3__c,Certification__c,Result__c from Student_Reports__c where Student_Name__c=:StudentDetails];
    }
    else{
    system.debug('ERROR: Select any Name');
    }
    }
    }

    Please correct the code
    Thanks in advance

    SANJAY replied 7 years ago 1 Member · 0 Replies
  • 0 Replies

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

Popular Salesforce Infographics