You need to sign in to do that
Don't have an account?
Pun!5h3r
Create a parent to child to child relationship
I want to create some query like:
I have to pass transaction object record as a parameter. How to Break down the query and accomplish it.
Note: I should get Transaction record which has fields of the child object dc__Transaction_Line_Items__r and sub child object Product__r
SELECT ID, Name , dc__Contact__r.Account.Name, (SELECT ID, (select id from product2__r) From dc__Transaction_Line_Items__r) From dc__Transaction__c
I have to pass transaction object record as a parameter. How to Break down the query and accomplish it.
Note: I should get Transaction record which has fields of the child object dc__Transaction_Line_Items__r and sub child object Product__r
SOQL: Parent to Child and Child to sub child relationship please refer the below link for reference.
- https://developer.salesforce.com/forums/?id=906F0000000BIttIAG
Hope it will be helpful.Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Rahul Kumar
Thanks for a quick reply, If you could please elaborate how do we breakdown query from the given link.
Only one level of parent-to-child relationship can be specified in a query. For example Case is child of Account hence you can write like:
SELECT Id, (SELECT Id, CaseNumber FROM Cases) FROM Account WEERE Id = '0019000000000000'
If you go one more level like:
SELECT Id, (SELECT Id, CaseNumber, (SELECT id FROM CaseComments ) FROM Cases) FROM Account WHERE Id = '0019000000000000'
You will get error something like: MALFORMED_QUERY: SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.
From Child to Parent:
No more than five levels can be specified in a child-to-parent relationship. For example:
SELECT Id, Parent.CaseNumber, Parent.Account.Name, Parent.Account.Owner.Name, Parent.Account.Owner.Profile.CreatedBy.Name FROM CaseComment