-
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 7 Salesforce Sales Dashboards for 2022-2023
Salesforce Sales dashboards are great tools for taking full advantage of CRM capabilities. The platform allows you to collect all the information about your company,…
Upcoming Salesforce Events and Releases - 2021
Every year Salesforce comes up with an extravagant and magnificent series of events and 2021 is no different. A lot of exciting events and releases…
Salesforce Engage: Ideal Link Between Marketing and Sales
The cohesion between the marketing and sales teams is vital in the business world as it allows concerted efforts, speeding up sales cycles, and optimizing…
Popular Salesforce Videos
How to Create a Landing Page in Salesforce Account Engagement (Pardot)?
A landing page acts as a customized doorstep for potential clients. It's crucial because it guides their focus toward a particular action, such as signing…
Learning Path and Pay Scale for Salesforce Profiles
Now it's high time to know about the Learning Path for the different Salesforce profiles. In this video, you also got to know about the…
Salesforce Flow Best Practices: Salesforce Flow Design Patterns
Salesforce Flow Design Patterns from Fundamentals to Mastery. In this session, we will talk about the top 10 Salesforce Flow best practices. We will talk…
Popular Salesforce Infographics
Sales Productivity: Tips to Overcome Productivity Challenges
Growing sales is the cornerstone of business success. Whether you're a startup or an established enterprise, the objective remains the same: Increase Revenue, Expand your…
Salesforce Admin Certification Path
This infographic helps you to understand the complete certification path to become Salesforce Administrator which includes accreditation body, pre-requisites, eligibility criteria, examination format and career…
Introduction to The Salesforce Architecture
Have you ever wondered what is so special about Salesforce? How does it manage to accomplish so much in such less time? Well, the secret…