-
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
Notes on Importing Data | Salesforce Developer Guide
Required Salesforce Editions It is available in Salesforce Classic (not accessible by and large association) and Salesforce Lightning Experience both. Your Salesforce version figures out…
Mastering Salesforce Packages: Managed vs. Unmanaged
Salesforce packages simplify application development, deployment, and distribution in the Salesforce ecosystem. This blog explores Salesforce packages, their significance for administrators, developers, and users. We'll…
All You Need to know About Salesforce Lightning Component Lifecycle
A Lightning component is instantiated, rendered, and rerendered during its lifecycle. Components are only re-rendered when there's a program or value change that requires re-rendering.…
Popular Salesforce Videos
Share Visualforce Pages Between Classic and Lightning Experience | Salesforce Trailhead
Visualforce Pages should be created correctly such that they behave properly whether they run in Salesforce Classic or Lightning Experience. Detecting and Responding to the…
Salesforce Lightning User Tips & Tricks Spring 2021
This session is one of our most popular Webinars. It includes tips and tricks that any Salesforce user will find helpful. Learn Salesforce shortcuts that…
How To Use Dynamic Prefill Link of Formstack | Learn Salesforce Series by Algoworks
Learn how to use ‘Dynamic Prefill Link’ of Formstack in 4 easy steps! 1. Introduction Short introduction of FormStack and its uses. 2. The need…
Popular Salesforce Infographics
How to Choose the Right Salesforce Partner
Choosing the right partner is a key factor that could make or break your project’s success. Salesforce is a mighty CRM platform, and that’s why…
A Better Way To Manage Your Salesforce | An Infographic
New software allows sales executives to see exactly where and how sales reps spend their time. These improved analytics give management a solid basis for…
Salesforce Agentforce - The AI assistant for business growth
This infographic highlights Salesforce Agentforce, an AI-powered assistant designed to enhance business growth through automation, insights, and intelligent task management. It explains how Agentforce transforms…