You need to sign in to do that
Don't have an account?
aiyaz_SFDC
SOQL Query question (Parent to Child)
Hi,
I have a custom object (Bonds) that has a lookup field that displays Accounts which creates the Child-to-Parent relationship.
Currently i'm working with Visualforce to display Accounts detail along with just the current month's Bonds. When I view the WSDL I see that Bonds is set as a related object (Bonds__r). When I set up a SOQL query i'm unsure whether I am on the right track although I believe I should be using the "__r" notation when referencing the relationship. Below is the query:
Account[] ab =
[SELECT Name, (SELECT BondVol__c FROM Bonds__r) FROM Account]
In order to distinguish between a custom field name and a custom relationship name we have use a different suffix. Fields and objects get "__c" and relationships get "__r". Again, this applies to custom relationships (and fields/objects) only.
The enterprise WSDL and API Describe calls describe all the names as you should use them in Visualforce and Apex.
Thanks for the tip.
With that in mind, i'm assuming it makes sense on how i queried the BondVol__c field from the Bonds__r custom relationship (related to Account) ?
[SELECT Name, (SELECT BondVol__c FROM Bonds__r) FROM Account]