-
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
Salesforce Spring ’20 – The Top Features
The Spring ’20 release of Salesforce is coming in mid-February 2020. Here are some of the new features that will make life easier for users,…
MFA (Multi-Factor Authentication) in Salesforce
Introduction MFA is a special security feature provided by Salesforce that provides an extra layer of protection against suspicious or unauthorised logins. After enabling the…
Wonder How Salesforce Commerce Cloud Provides Seamless User Experiences for eCommerce Businesses
Shifting primary demand from offline shopping to online shopping, eCommerce innovations have revolutionized the industry. As customers indulge in online shopping, they seek to demand…
Popular Salesforce Videos
Salesforce Service Cloud Training Videos For Beginners
This Salesforce Training video will explain how to create case assignment rules, creating a web-to-case form in Salesforce. The demo in this video will help…
Salesforce Connect ( Cross-Org Adaptor ) | Salesforce Tutorial
This video will talk about external objects using Salesforce Connect, also known as Cross-Org Adaptor. 00:00 Introduction 00:29 Introduction to Cross Org Adapter 01:51 Create…
What are Apps in Salesforce?
Apps in Salesforce are Service, Marketing, Content, Salesforce Chatter, Service Console, Salesforce CMS, Test, Sales, Salesforce Scheduler Setup, Community, Sales Console, Lightning Usage App, Bolt…
Popular Salesforce Infographics
Average Salesforce Salaries 2019
This Infographic gives Salesforce professionals an idea about where they sit in the market and what salary they can expect, using data from the Mason…
9 Steps for Building a Useful Price Quote Template
Price quotes are among the most fundamental components of a sales unit’s library, yet too many sales managers treat quotes as a perfunctory measure that…
The Salesforce Lightning Platform for Employee Engagement: Key Findings
Salesforce provides a system of engagement across the entire employee lifecycle that enables organizations to connect multiple back-end systems of record with one system of…