You need to sign in to do that
Don't have an account?
r naresh
how to fetch records from parent to child?
here parent is department and child is employee
vf page
-------------
<apex:page controller="depttoemp">
<apex:form >
<apex:pageblock title="dept to emp">
<apex:pageBlockTable value="{!dept}" var="d">
<apex:column value="{!d.id}"/>
<apex:column value="{!d.name}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
controller
--------------
public with sharing class depttoemp {
public list<Department__c> dept{get;set;}
public list<Employee__c> emp{get;set;}
public depttoemp ()
{
string soql='select id,name,(select id,name from Employee__r)from Department__c';
dept=Database.Query(soql);
}
}
im getting this problem
====================
System.QueryException: Didn't understand relationship 'Employee__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
vf page
-------------
<apex:page controller="depttoemp">
<apex:form >
<apex:pageblock title="dept to emp">
<apex:pageBlockTable value="{!dept}" var="d">
<apex:column value="{!d.id}"/>
<apex:column value="{!d.name}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
controller
--------------
public with sharing class depttoemp {
public list<Department__c> dept{get;set;}
public list<Employee__c> emp{get;set;}
public depttoemp ()
{
string soql='select id,name,(select id,name from Employee__r)from Department__c';
dept=Database.Query(soql);
}
}
im getting this problem
====================
System.QueryException: Didn't understand relationship 'Employee__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
I guess your child relation ship name is "Employees"
So use the following query: -
string soql='select id,name,(select id,name from Employees__r)from Department__c';
And don't forget to mark this answer as best, if answer this helps you :-)
--
Regards,
Grazitti Team
Web: www.grazitti.com
All Answers
Navigate to child object i.e. Employee then locate the field that is reference to Department.
On the field details check the relationship name. append __r with the name.
For example, in above image it will be Donations__r
Let us know if this helps!
I guess your child relation ship name is "Employees"
So use the following query: -
string soql='select id,name,(select id,name from Employees__r)from Department__c';
And don't forget to mark this answer as best, if answer this helps you :-)
--
Regards,
Grazitti Team
Web: www.grazitti.com