0

Inner query in soql can only happen for master-detail relationship or also for lookup relationship?

Inner query in case of master detail as below :

SELECT ID, (SELECT Amount FROM Opportunity) FROM Account;

  • Also why the above inner query is not working ? – xyz sfdc Aug 21 '15 at 3:34
2

Works for lookup relationship as well. The reason the above query is not working is because you need to use plural form of Opportunity.

2

You can do on both master-detail and lookup relationships. When writing an inner query you need to use the Child Relationship name of the master-detail/lookup relationship. For standard objects it's typically the plural name of the child object as per Lance's answer, however for custom relationships you define the Child Relationship name when you create the relationship and you need to always append __r at the end:

[SELECT Id, (SELECT Id FROM MyCustomObject__r) FROM Account]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.