You need to sign in to do that
Don't have an account?

How to call fields to child obj from another child obj
Hi,
I have three objects Obj1,Obj2 and Obj3
Relation between these three objects is Obj2 and Obj3 are the childs for Obj1
Requirement - i have created a visual force page in Obj2 and i want to call list of Obj3 records where Obj2 related with Obj1.
Thanks in Advance.....
If your requirement is to fetch all Obj3 records related one Record of Obj1 to which this Obj2 record is asociated frm which this VF page is called,
Then once you call the page, store Obje1 id in variable and query all Obj3 records where Obj1 id is the one which you stored in variable.
Mark this as answer and hit kudos if this post helps you.
Hi,
Thanks for the reply.
Can you please send a sample code?
Lets take up standard objects for example :
Opportunity(Obj 3) and contacts(Obj 2) are childs of account(Obj 1).
Following page called from contact, fecthes all opportunities of the account asociated with the contact from where this VF page is called.
System debug will show you all the opportunities of the account.
-- VF page--
<apex:page standardController="Contact" extensions="FetchRecordsController">
<apex:form >
<apex:pageblock ></apex:pageblock>
</apex:form>
</apex:page>
-- Controller --
public with sharing class FetchRecordsController {
Contact ContactRec;
Id AccountID;
List<Opportunity> OpportunityList = New List<Opportunity>();
public FetchRecordsController(ApexPages.StandardController controller) {
ContactRec = (Contact)controller.getrecord();
AccountId = ContactRec.AccountId;
OpportunityList = [Select id,name from Opportunity where AccountId =:AccountId ];
System.debug('**All Opportunity Records** of'+ AccountId + 'are' +OpportunityList );
}
}
Hit kudos by clicking the blue star and mark this as answer if it helps you.
thanks and regards,
Yoganand.
Thanks for the example, I have written a class for the standard objects it
was working fine.
But i got stuck doing it for custom objects.
Can you please help how to do on custom objects on the same scenario.
Thanks.......
How to do it for custom objects
public class test {
public List<Contact> cont{get; set;}
public Id oppid;
public Id AccountId;
public test(ApexPages.StandardController controller) {
oppId= controller.getRecord().Id;
system.debug('*********************OppId'+oppId);
try
{
Opportunity opp=[Select id,AccountId From Opportunity Where id=:oppId];
system.debug('Opportunity%%%%%%%%%%'+opp.AccountId);
cont=[Select LastName,FirstName From Contact Where AccountId=:opp.Accountid];
}
catch(Exception e)
{
system.debug('Exception'+e);
}
}
}
Lets say Account = Obj1
Opportunity = Obj2
Contact = Obj3