I want to write single Query to fetch opportunity, account and Account's Contact based on opportunity Id. It's like Child-> Parent -> Child relationship

Select id, Amount, CloseDate, Account.Name,(Select Contact.Name From
Account.Contacts) from Opportunity Where id=''

You can't query "up then down". Instead, you can query from the Account.

SELECT Name...,
       (SELECT Name... FROM Contacts),
       (SELECT Name, Amount, CloseDate... FROM Opportunities WHERE Id = :oppId)
FROM Account
   WHERE Id IN (SELECT AccountId FROM Opportunity WHERE Id = :oppId)
| improve this answer | |

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.