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
sgsssgss 

Create a custom object 'A', 'B' and 'C'. Establish 'Master Detail' relationship between them such that 'C' is junction object... SOQL query on 'C'(created above) to retrieve all records of 'C' with name 'John' along with parent details.

Can anyone help me with this?

Create a custom object 'A', 'B' and 'C'. Establish 'Master Detail' relationship between them such that
'C' is junction object.
SOQL query on 'C'(created above) to retrieve all records of 'C' with name 'John' along with parent details.
 
Akshay_DhimanAkshay_Dhiman
Hi Supriya,

This just an example of how the parent-child query works...

1.  Ways of writing Parent - Child Queries for Standard Objects

    Select Id, Name, (Select Id, LastName from Contacts where Lastname='Frank') from Account

2.  Child-Parent 
    Select Id, LastName, Account.Name from Contact

3.  Ways of writing Parent - Child Queries for Custom Objects

     Select Id, Name, (Select Id, Name from Custom_Object2s__r) from Custom_Object1__c
     example 3.Select Id, Name, Custom_Object1__r.Name from Custom_Object2__c
     example 2. Select Name, PrarentObject.FieldName FROM C_Object Where Name =: 'John'

Hope this might helps...

Thanks
Akshay
sgsssgss
Thanks a lot.
sgsssgss
Can you Explain this considering above problem
Parent 1 : A
Parent 2 : B
Child :  C
on C
parent to child
and child to parent both .
C custom objectcustom Object Acustom Object B


I am not getting whee to use __c and where to use __r
 
Akshay_DhimanAkshay_Dhiman
Hi Supriya,

The "__c" stores the salesforce Id(only) and "__r" should be used to get additional fields other than Id in your SOQL. Think of
_r as means to JOIN the relating table/object and _c as the foreign key. So using _c won't require an additional JOIN and hence might be more performance v/s _r.

If you found this answer helpful then please mark it as best answer so it can help others.

Thank You
Akshay