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
RajaganagavelRajaganagavel 

Unable to retrive the records using relationship SOQL Queries Child to Parent

Hi Guys,

In my ORG, I have two custom objects named as follows.

Here Warehouse is Parent Object and Product is Child object.

Also, master-detail relation ship has created with Product_Warehouse_Location field in Product object

Custom Objects

But I'm trying to retrive the record using child to parent  relationship SOQL queries between the objects

SOQL Query
I'm getting  the following error in Query editor window.

Product_Warehouse_Location__c, Product_Name__c ,Warehouse__r.Name FROM Product__c
                                                ^
ERROR at Row:1:Column:65
Didn't understand relationship 'Warehouse__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.



Please someone help me on this. Help to identify whats wrong with my query.

Custom Object Parent API Name : Warehouse__c
Fields:
Name
Warehouse_Name__c
Warehouse_Location__c

Custom Obejct Child API Name : Product__c
Fields:
Name
Product_Name__c
Product_Warehouse_Location__c ---Master-Detail(Warehouse)



 
Best Answer chosen by Rajaganagavel
Ajay K DubediAjay K Dubedi
Hi Rajaganagavel,

In this case, you can query from child to parent with the help of field specified for master-detail relationship on the child object.

Please use the below query to resolve your issue:
Select Id, Name, Product_Name__c ,Product_Warehouse_Location__r.Name FROM Product__c

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi

All Answers

Sunil RathoreSunil Rathore
Hi,

Please use this following query:

Select Id,Product_Warehouse_Location__c, Product_Name__c ,Product_Warehouse_Location__r.Name FROM Product__c

Let me know if it solves your problem.

Many Thanks,
Sunil Rathore
Ajay K DubediAjay K Dubedi
Hi Rajaganagavel,

In this case, you can query from child to parent with the help of field specified for master-detail relationship on the child object.

Please use the below query to resolve your issue:
Select Id, Name, Product_Name__c ,Product_Warehouse_Location__r.Name FROM Product__c

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
This was selected as the best answer
RajaganagavelRajaganagavel
Hi Sunil / Ajay,

Thanks for your prompt response.

Your query works like charm. Now, I understand that only relationship field should be appended with __r in that query.

Thank you so much guys!!