-
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
Top Salesforce Trends to Watch Out in 2021
2020 year has been a challenging year for everyone no doubt. The pandemic, global lockdown, and economic crisis have affected everyone’s personal lives and the…
A Step-by-step Guide to Successfully Implement Salesforce
Salesforce is one of the world’s most prevalent and persuasive Customer Relationship Management (CRM) solutions for marketing, sales, and service. Being one of the leading CRM systems in the…
Popular Salesforce Videos
Introduction To Salesforce Apex | DataType | Collection | Conditional Statements
In this video salesforce apex hours creators provides an introduction to Apex. Apex enables developers to access the Salesforce platform, back-end database and client-server interfaces…
How to Manage Your Data and Contacts in Salesforce Marketing Cloud
Learn how contacts are counted and how data is structured in Marketing Cloud. This video explores how Marketing Cloud receives data from many sources and…
What are Roll-up Summary Fields in Salesforce? | How to create them?
In this video, Shrey is not only teaching but also demonstrating to you "What are Roll-up Summary Fields in Salesforce?". You will be learning: 1.…
Popular Salesforce Infographics
Build On Your Salesforce Service Cloud With Cognitive Search
Employees waste around 20% of their time looking for information to do their job. That’s a lot, isn’t it? This means there is one giant…
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…
Salesforce Training Simplified
Salesforce training simplified. Create a proven Salesforce Training model that will derive your end-users and impress your executive team. Prepare, deploy, maintain. Go through this…