-
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
An Introduction to Salesforce Consumer Goods Cloud
Salesforce has introduced Consumer Goods Cloud, a new industry product that enables companies related to consumer goods to optimize revenue growth and maximize ROI with…
Purpose and Perks of Salesforce Subscription
As a business owner, you know customer relationships are key to success. You also understand that managing those relationships can be time-consuming and expensive. A…
Key Considerations for Developing AppExchange Strategy
When developing an AppExchange strategy for your Salesforce app, several key factors are important to keep in mind to ensure success and maximize the impact…
Popular Salesforce Videos
How to Delete Multiple Contacts at Once | Salesforce Tutorial
Do you need to delete a bunch of records? Don't want to delete records one by one? This video shows you several ways to delete…
Get Started with Process Builder
Get started with process builder -- and replace that ridiculously and ever-growing list of workflow rules with easier to understand, more extensible processes. This video…
How to Edit or Change Product Schedules in Salesforce
Use product schedules to determine the payment and delivery cycles for products that are paid or delivered over time. In Lightning Experience, customize schedules with…
Popular Salesforce Infographics
The 10.5 Commandments of Salesforce Users
This great piece of visual goodness presents the 10 commandments every Salesforce user needs to follow. Make sure every single one of these practices is…
How Salesforce is Beneficial For Your Business
There is a saying frequently heard many times which is “ Customer is a King”. So, a business needs to do everything to satisfy the…
How To Upgrade Your Business With Salesforce?
Salesforce has been stretching the possibilities of business growth right from its inception in 1999. Its fierce business model attracted people who eventually moved to…