-
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
What is a Salesforce AppExchange App - Here's All You Need to Know
A marketplace called AppExchange provides products including software, parts, and consulting services. Salesforce AppExchange App is a platform that mainly improves a company's business process.…
Salesforce Alternatives: Top 10 Competitors in 2021
Salesforce Alternatives: Top 10 Competitors in 2021 There are many Salesforce alternatives on the market today. In fact, with over 800 CRM platforms, the number…
Popular Salesforce Videos
Salesforce Marketing Cloud Connect: Subscriber Key Migration
We demo how leveraging a subscriber key migration to remove duplicate subscribers from Sales or Service Cloud in Marketing Cloud while minimizing data loss. Explore…
Salesforce Consumer Goods Cloud Demo
Salesforce Consumer Goods Cloud is an intelligent, seamless B2B CRM solution specifically designed for the consumer goods industry. Watch this video to learn more.
Salesforce Loves Small Business
Running a small business takes a lot of heart during even the best of times. 2020 has presented a series of challenges that have hit…
Popular Salesforce Infographics
Salesforce Data Migration: Best Practices to Ensure a Smooth Transition
Migrating data to Salesforce can be a daunting task, but it doesn't have to be. By following a few best practices, you can ensure a…
How Your Business Can Leverage The Power of Salesforce Community Cloud?
Community Cloud is a cloud-based platform that enables businesses (small, medium, big) to build exceptional and interactive CRM-powered portals, forums, and sites that are faster…
Which Salesforce Certification is Right for You?
This informative infographic will help readers to decide which Salesforce certification is right choice for their Salesforce career.