You need to sign in to do that
Don't have an account?
smitra
Retrieving Related List by SOQL query and disply in a visualforce page
I have two custom objects as master detail relationship.Inorder to retrieve related list from the master record using SOQL query and display it in visualforce page
Here "detail__rr" is child relation ship name between child and master object. you can get child relation ship name from Master detail field on child object's schema. there child relation ship is available and then please append "__r"
All Answers
You can use parent object ID to query related childs in SOQL or you can use
apex:relatedList
Let's say I have two objects Master and Detail ( Child object) ten in order to display related list of child record we need to apply SOQL like below
List<Master__c> ListOFMasterRecords = new list<Master__c>([select id (select id from Detail__r)from Master__c]);
you can fire relationship query which will give you all the detail(related list records) records for each of the master record.
Have a look at this : How to fetch related list records using Relationship query in apex.
Hit kudos and mark this as answer if this helps you in any way.
Thanks,
Lets Elaborate the Example Using Account and Contact.
So your query will be
How to access ?
Here "detail__rr" is child relation ship name between child and master object. you can get child relation ship name from Master detail field on child object's schema. there child relation ship is available and then please append "__r"
Hi thanks all for your response.
Now can you tell me incase if I need to sort the related list that I have fetched what is the solution for that.
what best suits with this code snippents inorder to sort related list
<apex:pageBlockTable value="{!relatedContacts}" var="val">
<apex:column value="{!val.name}"/>
<apex:column value="{!val.email}"/>
</apex:pageBlockTable>
Thanks for marking my answer please hit STAR icon to give me KUDOS