function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ron McCrereyRon McCrerey 

How do I form a SOQL query for the child of Product2 whose parent is a Product2?

How do I form a SOQL query for the child of Product2 whose parent is a Product2?
Best Answer chosen by Ron McCrerey
Neetu_BansalNeetu_Bansal
Hi Ron,

You need to use the child relationship name instead of 'Products__r'. When you created Master detail to Product on Product, you should have provided a child relationship name, use that.

If still you face some issue, you can share your salesforce org login credentials and I will help you out. You can contact me either on my gmail id: neetu.bansal.5@gmail.com or Skype id: neetu.bansal.5

Thanks,
Neetu

All Answers

Neetu_BansalNeetu_Bansal
Hi Ron,

Try using this query:
Select Id, (Select Id from Products__r) from Product2
Here in the inner query 'Products' is the child relationship name which I provided while creating relationship. Replace it with your child relationship name.

Let me know if you need any other help.

Thanks,
Neetu
Ron McCrereyRon McCrerey
Here is my simplified query
Select Product2.Total_Cost__c, (Select Product2.Total_cost__c from Products__r) from Prouduct2 where Product2.Status__c = 'Available'  

Get the following error
Didn't understand relationship 'Products__r' in FROM part of query call.
Neetu_BansalNeetu_Bansal
Hi Ron,

You need to use the child relationship name instead of 'Products__r'. When you created Master detail to Product on Product, you should have provided a child relationship name, use that.

If still you face some issue, you can share your salesforce org login credentials and I will help you out. You can contact me either on my gmail id: neetu.bansal.5@gmail.com or Skype id: neetu.bansal.5

Thanks,
Neetu
This was selected as the best answer