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
Venky1219Venky1219 

Getting child object values using parent Id

Hi all,

I have Responses__c and Response_Type__c objects . Response_Type__c is parent to Responses__c . Now I have Response_Type__c Id so written Query as follows to get Response_type__c fields as well as Responses__c fields 

 

List<Response_type__c> rtList = [select id,name,(select id,name from responses__c) from Response_type__c  where id =: rt.id];

 

Now it raising error 

 

Error: TestController Compile Error: Didn't understand relationship 'responses__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.

 

then I changed the query as follows

 

List<Response_type__c> rtList = [select id,name,(select id,name from responses__r) from Response_type__c  where id =: rt.id];

 

still the same error 

 

Error: TestController Compile Error: Didn't understand relationship 'responses__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.

 

 

so please help me in resolving this. please explain what is root cause

Best Answer chosen by Admin (Salesforce Developers) 
Dhaval PanchalDhaval Panchal
Do one thing, go to child object Responses__c, click on lookup field responses__c which is related to Response_type__c, you will find "Child Relationship name" there. copy that name and add '__r' after that name, use this name in inner query.

All Answers

Dhaval PanchalDhaval Panchal
Do one thing, go to child object Responses__c, click on lookup field responses__c which is related to Response_type__c, you will find "Child Relationship name" there. copy that name and add '__r' after that name, use this name in inner query.
This was selected as the best answer
Venky1219Venky1219
Thank you so much I got it...
Soumya BeheraSoumya Behera
Thanks you Dhaval Panchal...