You need to sign in to do that
Don't have an account?
Camzilla
Display Relationship Query Result
Im not using a sandbox but testing towards the actual database. This is the query I'm trying:
Select (Select Id, CurrencyIsoCode, Postcode_lookup__c From Post_code_company__r) From Postal_code_lookup__c
The result Im looking for is not objects itselfs, but I want a list of the child records. Im not sure how to acomplish this since there seem to be no __r object to getch data from? How can you do this query?
I figured it out myself, to access the children you can search through a relation, but since the realtion compares with a whole object you have to specify a field. Like so;
[Select Id, CurrencyIsoCode, name from PC_Company__c where Postcode_lookup__r.Name = :searchString]
All Answers
Hi Camzilla,
You can query the child object's records as follows,
Parent__c p = [Select id, name from Parent__c where <Condition> limit 1]; //Query the parent record id first
List<Child__c> childList = [Select id,name,ParentID__c from Child__c where ParentID__c =: p.id); //List of all childs__c of the parent__c (p.id)
So, now childList will have all the records that matches the parentID__c as p.id.
Hope this will help you...!
Please don't forget to give kudos and mark this as a solution, if this works out.
It is the child relationship name that should be mentioned in the inner query and not he name of the child object itself.
If you open to the lookup field in the child object, you will get the child relationship name which you should use in the inner query.
Hey KamatchiDeviR,
I have more than one child, so your query doesnt really work for me.
Yo jungleee,
I know this already, and thats what i tried. You'll get a result list of an object with its children..
I figured it out myself, to access the children you can search through a relation, but since the realtion compares with a whole object you have to specify a field. Like so;
[Select Id, CurrencyIsoCode, name from PC_Company__c where Postcode_lookup__r.Name = :searchString]
I was not sure if you were aware of that. Anyways here's what you wanted;