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
Gaurav Agnihotri 11Gaurav Agnihotri 11 

Error in SOQL master Detail (custom)

trying to create a SOQL on the Master - Detail

Master: Opportunity
Detail: Opportunity_Split_Reporting_Lens__r
field : Opportunity_Name ( Id of opportunity)

I am able to go from child to parent 
select Opportunity_Account_Name__c from  Opportunity_Split_Reporting_Lens__c

How can i get child record from parent?
select name, (select name from Opportunity_Split_Reporting_Lens__r)  from Opportunity limit 5
Error message:
ERROR at Row:1:Column:32
Didn't understand relationship 'Opportunity_Split_Reporting_Lens__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.
Best Answer chosen by Gaurav Agnihotri 11
Maharajan CMaharajan C
Hi Gaurav,

Check your child relationship name in your opportunity lookup field at Opportunity_Split_Reporting_Lens__c object.

don't use the object api name with __r.  you have to use the    Child Relationship Name __r      from the Opportunity lookup field in  Opportunity_Split_Reporting_Lens__c.

Go to --> Opportunity_Split_Reporting_Lens__c --> open Opportunity lookup field --> copy the Child Relationship Name --> then use that name in your query with __r.

Please refer below screenhot:

User-added image

based on my screenshot i have to use like: 

Select Name, (select id from members__r) from Opportunity

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj C

All Answers

Maharajan CMaharajan C
Hi Gaurav,

Check your child relationship name in your opportunity lookup field at Opportunity_Split_Reporting_Lens__c object.

don't use the object api name with __r.  you have to use the    Child Relationship Name __r      from the Opportunity lookup field in  Opportunity_Split_Reporting_Lens__c.

Go to --> Opportunity_Split_Reporting_Lens__c --> open Opportunity lookup field --> copy the Child Relationship Name --> then use that name in your query with __r.

Please refer below screenhot:

User-added image

based on my screenshot i have to use like: 

Select Name, (select id from members__r) from Opportunity

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj C
This was selected as the best answer
Raj VakatiRaj Vakati
Refer this links

http://www.sfdcpoint.com/salesforce/relationship-query-apex-salesforce/
http://www.sfdc99.com/2013/06/24/example-how-to-write-a-cross-object-soql-query-part-2/
http://sfdc.arrowpointe.com/2007/01/19/set-child-relationship-name-on-custom-relationship-fields/
http://www.riptutorial.com/salesforce/example/15600/soql-query-to-reference-parent-object-s-fields
Gaurav Agnihotri 11Gaurav Agnihotri 11
Thanks! Mahajan and Raj for your help. Much appreciated!