+ Start a Discussion

how to Query parent to child

I have process in salesforce in such a way opportunity we can relate this opportunity to this lookup field parent_opportunity__c . Which relates opportunity to other parent opportunity.

I want to write a query parent to child :select id,(select id from opportunity where parent_opportunity__c!=null) from opportunity where parent_opportunity__c=nullI have worked with different scenarios i cant able to crack it

select id,name,(select id,name from parent_opportunity__r) from opportunity this is showing error and

select id,name,(select id,name from opportunity) from parent_opportunity__c this is also error
sandeep sankhlasandeep sankhla
Hi D,

Please check the below link and let me know if you still face any error in making these query..

It is simple..you just need to provide the relationship name in relationship query so provide the correct relationship name instead of field name then it will work like a charm..


try and let me knwo if you need any help

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Salesforce Certified Developer 
Is the parent_opportunity__c a Lookup field on Opportunity Object? If it is, you can try the following query:
select id,name, parent_opportunity__r.name from opportunity where parent_opportunity__c!=null