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
Vijay sidaraddiVijay sidaraddi 

SOQL query for parent child relation getting error

HI Friends,

im trying to get the records for nested query in developer, i couldn ot able to do it can some one suggest me where im wrong 

SELECT ENQ_Project_Name__c,ENQ_AFE__c,ENQ_Inspection_Level__c,
                         (SELECT ENQ_QSC__c,ENQ_QSC_Contact__c FROM ENQ_Surveillance_Reports__c)
                          FROM ENQ_Assignment_Package__c 

Error message : 
ENQ_QSC__c,ENQ_QSC_Contact__c FROM ENQ_Surveillance_Reports__c)
ERROR at Row:3:Column:69
Didn't understand relationship 'ENQ_Surveillance_Reports__c' 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.

Apoorv Saxena 4Apoorv Saxena 4
Hi Vijay,

When using Sub-query you need to use child relationship name and if child is a custom object you need to append '__r' after the child relationship name.

So try this :
SELECT ENQ_Project_Name__c,ENQ_AFE__c,ENQ_Inspection_Level__c,
                         (SELECT ENQ_QSC__c,ENQ_QSC_Contact__c FROM ENQ_Surveillance_Reports__r)
                          FROM ENQ_Assignment_Package__c

Please mark this question as Solved if this helps you, so that others can view it as a proper solution.

Mahesh K 22Mahesh K 22
Hi Vijay
u did small mistack i .e  ENQ_Surveillance_Reports__c
   try this. ENQ_Surveillance_Reports__r  
becz of they have a realtionship(parent to child)
 so we keep it as  r in c