-
How to get child object records by check the checkbox of parent record
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
Log In to reply.
Popular Salesforce Blogs

How to retrieve the list of users based on Role Hierarchy in Salesforce?
How to retrieve the list of users based on Role Hierarchy in Salesforce: Sometimes, you need a multilevel hierarchy i.e. you need to view the…

Salesforce And Google Analytics Integration: All You Should Know
Are you looking for a tool that helps you manage and nurture your leads? Salesforce is a great choice. However, when it comes to generating…

Automation in the Insurance Industry: Benefits and Salesforce Use Cases
Unstructured data is the key pain point that drives companies from various industries towards automation, and insurance is no exception. With automation, you'll be able…
Popular Salesforce Videos
Salesforce Contact Tracing for Employees Demo
As businesses gradually reopen after worldwide closures, many people feel concerned about the second spike in COVID-19 cases. To ensure public safety, local officials have…
Understanding Service Cloud & Case Management in Salesforce
In this video, Shrey is not only teaching but also demonstrating the Basics of Salesforce Service Cloud and Case Management. You will be learning: 1.…
Salesforce Integration: How to Do it the Best Way?
Once you deploy Salesforce solutions to improve the operation of your enterprise, your next logical step is to enhance the overall functionalities by integrating Salesforce…
Popular Salesforce Infographics

Best Practices For Cleaning and Maintaining Salesforce Data [Infographic]
Once you’ve had Salesforce up and running for a while, your system’s data will need to be tidied up. Or if you’re looking to move…

How To Sell Better in 2020 | Tips From Salesforce Leaders
There are various things that you need to pay heed on while selling something. In 2020, where technology is ruling the world, and we are…

Key Benefits Of Using Salesforce CPQ
Improves productivity and efficiency with Salesforce CPQ. Automate contract amendments, usage pricing, and renewals using an innovative billing feature of Salesforce CPQ Still have a…