-
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
Integrate Your Vanilla-Community With Salesforce to Deliver Seamless, Efficient Support
According to a survey conducted by Gartner, 62% of millennials and 75% of GenZ customers prefer self-service instead of seeking assistance from support reps. As a result, online…
How to Leverage Salesforce Integration for Enhanced Customer Engagement: A Comprehensive Guide
Customer engagement has become the cornerstone of modern business success. With customers expecting more personalized, responsive, and intelligent interactions, businesses must leverage the best tools…
Salesforce Marketing Cloud: Your One-stop Marketing Solution
The Word-class CRM solution, Salesforce does not leave any room for doubts and connects brands and customers in the best possible way. With multiple cloud…
Popular Salesforce Videos
Salesforce Essentials vs Professional
In this video, Bradley Large answers some of the most common questions people have about Salesforce. He gives clear and concise answers to questions like:…
Salesforce Admin Beginners Tutorial - 3.1 - Salesforce Platform Basics
Salesforce is an innovative tool that can be very powerful when used properly. That’s why it’s important to find effective and trustworthy ways to learn…
Creating Datasets - Tableau CRM | Salesforce Tutorial
Recipes provide an easy way to update, combine and transform your sources into the datasets you'll use to drive your dashboards. You'll see how to…
Popular Salesforce Infographics
Take a look at the future of CPQ with this infographic!
Business-to-business sales, often referred to as simply B2B, used to be much less complex. But now, there is a lot that goes into these quotes…
Salesforce Admin Mind Map
As you study for your Salesforce Admin exam and certification, rely on this easy-to-use mind map to make critical connections to the information you need…
What Can Salesforce’ Non Profit Success Pack Provide You With?
The Nonprofit Success Pack NPSP (formerly known as "Nonprofit Starter Pack) is a set of managed packages developed and maintained by Salesforce.org and made available…