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 BirsinghVijay Birsingh 

SOQL on Master-Detail Relationships

Hello,

        I am a novice in writing SOQL statements concerning Master Detail relationships. I would like to know how I need to write a SELECT SOQL statement on these:

Master object: Opportunity
Detail object: Quote
Child Relationship Name: Quotes
Field Name: Opportunity

Basically, I want to extract the Id from Opportunity and add it to the other fields of the Quote object in a single SELECT SOQL statement. How do I proceed? 

Regards, 
Vijay.

Best Answer chosen by Vijay Birsingh
sandeep sankhlasandeep sankhla
Select (Select Id From Quotes) From Opportunity 

If you want to use inner query then this is what you should use...

Thanks

All Answers

Aron Schor [Dev]Aron Schor [Dev]
Vijay,

Maybe try this?
SELECT Opportunity__R.id, Name FROM Quote

This works is my system
SELECT Order_Header__R.Last_Invoice_Date__C, Description__c
    FROM Order_Detail__C

Order_Header__C is parent, Order_Detail__C is child in my system.

Aron
Arthur ImirzianArthur Imirzian
List<Opportunity> opportunities = [
	SELECT 
		Id, // opportunityFields1, opportunityFields2, etc
		(
			SELECT Id //, quoteFields1, quoteFields2, etc
			FROM Quotes__r
		)
	FROM Opportunity
];
Vijay BirsinghVijay Birsingh

Hello,

Thanks for your help, but in both cases, I am getting the error:

Didn't understand relationship... 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.

Kind Regards,
Vijay.

sandeep sankhlasandeep sankhla
HI Vijay,

Let me know if you got the solution or not so we can help..

Thanks,
Sandeep
Vijay BirsinghVijay Birsingh

Hello Sandeep,

I have not got any solution yet. I still need help.

Regards, 

Vijay

sandeep sankhlasandeep sankhla
I think you are using wrong relationship name while querying, please chcek if you are using correct one
sandeep sankhlasandeep sankhla
Select (Select Id From Quotes) From Opportunity 

If you want to use inner query then this is what you should use...

Thanks
This was selected as the best answer
Vijay BirsinghVijay Birsingh

Thanks Sandeep! 

It works fine now.

Regards,
Vijay.

mouhamadoune coulibaly 6mouhamadoune coulibaly 6
Hello 
Vijay Birsingh
I would like to know how to do a Master-detail Soql query please I'm a beginner 
Regards
Boopathi Muniyandi 4Boopathi Muniyandi 4
@Vijay Birsigh - what was the solution for your problem ?