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;

1
  • Also why the above inner query is not working ?
    – xyz sfdc
    Aug 21, 2015 at 3:34

2 Answers 2

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.

3

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]
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .