-
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
A Guide To Writing Your Salesforce Administrator Resume
A Salesforce Administrator ensures companies experience the full potential of Salesforce and its technology. With an average starting annual salary of $79,000 and a 400% growth…
5 Significant Benefits of Salesforce CRM Testing
Providing superior customer service is no longer a choice for businesses, it has rather become a necessity to sustain in this competitive world. However, providing…
Top 10 Forecasted CRM Trends In 2021 | Salesforce
Times are changing, which means implementing innovations and new ways of interacting with this simple business tool for CRM software users. What’s going to be…
Popular Salesforce Videos
Salesforce Einstein – CRM Stepping Into The World Of AI
We belong to a hyper-connected world these days where each and every step we take is an onslaught of data. So for this world what…
Use Aura Component in Screen Flow | Salesforce Flow Builder Tutorial
Hello Trailblazers, In this video, we will learn how to use Aura Component in Salesforce Screen Flow. How to validate the Lightning Component Input from…
Using Lambdas to Overcome Salesforce Governor Limits
Salesforce is a great CRM product, but it has some limitations that can prove troublesome depending on the situation. Since each org has to share…
Popular Salesforce Infographics
Boost Sales and Marketing with Salesforce Einstein 1
Salesforce Einstein 1 is a suite of artificial intelligence (AI) tools designed to enhance business efficiency and decision-making. Around 80% of customers expect companies to…
How IT Leaders Can Build Employee Advocacy | Salesforce Infographic
We created the APAC Employee Engagement report based on this research, to provide key insights that are critical to IT and people leaders now and…
Infographic: 3 Trends That’ll Transform Small Business Growth in 2018
If you’re hoping to successfully grow your small business this year, you need to stay on top of the newest trends. Not sure where to…