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
JamesHaworthOncamJamesHaworthOncam 

SOQL subquery not working - even when using Child Relationship Name

Hi,

I'm trying to build a query that has a subquery:
SELECT Entity_to_Pack__c, Name, PBSI__Customer__r.Name, PBSI__Contact__r.Name, PBSI__Mode_of_Delivery__c, PBSI__Contact__r.Phone, PBSI__Contact__r.Email, (SELECT PBSI__Estimated_Ship_Date__c, PBSI__Item__r.Name, PBSI__Quantity_Needed__c, Id FROM Sales_Order_Lines__r), PBSI__Customer__c FROM PBSI__PBSI_Sales_Order__c WHERE Id = 'a151r00000EaSFm'
For some reason, even though I am using the Child Relationship Name from the master-detail, I'm still getting the following error:

PBSI__Quantity_Needed__c, Id FROM Sales_Order_Lines__r), PBSI__Customer__c
                                  ^
ERROR at Row:1:Column:458
Didn't understand relationship 'Sales_Order_Lines__r' in FROM part of query call. 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.


See below Child Relationship Name from the master-detail field:
User-added image
Best Answer chosen by JamesHaworthOncam
JamesHaworthOncamJamesHaworthOncam
Solution from Trailblazer Community:

Amnon Kruvi
Hi James,

It looks like this is a managed object, so I'm assuming this relationship is also a managed field. Could you try adding PBSI__ before Sales_Order_Lines__r?