+ Start a Discussion
SHAIK MOHAMMAD YASEENSHAIK MOHAMMAD YASEEN 

query first master object name from second master object through junction object

Hi All,

I have three objects obj1, obj2, obj3 where obj2 is junction object for obj1 and obj2.

now my requirement is i have to retrive obj1 name from obj3 through query.

Please help me with sample query for the same. Thansk


Best Regards,
Mohammad Yaseen
 
Best Answer chosen by SHAIK MOHAMMAD YASEEN
Deepak Maheshwari 7Deepak Maheshwari 7

Hi,

 

This is possible.
Let us suppose obj1=Rig__c, obj3=Well__c, obj2=Rig_Deployment__c.

Obj2 is junction object.

 

So use the below query:

SELECT Name, (SELECT Scheduled_Completion_Date__c,Well__r.Name FROM Rig_Deployments__r  WHERE Completion_Date__c = NULL )
FROM Rig__c

 

For more information you can take reference of below link:

 

http://kingkoo-salesforce.blogspot.in/2012/12/how-to-write-soql-to-traverse-across.html

 

Thanks

Deepak

dpkm20@gmail.com

All Answers

Anurag SaxenaAnurag Saxena
Hi Shaik,

Refer the links

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships.htm

http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/

https://salesforce.stackexchange.com/questions/73502/soql-best-practices-with-multiple-junction-objects
Thanks
Deepak Maheshwari 7Deepak Maheshwari 7

Hi,

 

This is possible.
Let us suppose obj1=Rig__c, obj3=Well__c, obj2=Rig_Deployment__c.

Obj2 is junction object.

 

So use the below query:

SELECT Name, (SELECT Scheduled_Completion_Date__c,Well__r.Name FROM Rig_Deployments__r  WHERE Completion_Date__c = NULL )
FROM Rig__c

 

For more information you can take reference of below link:

 

http://kingkoo-salesforce.blogspot.in/2012/12/how-to-write-soql-to-traverse-across.html

 

Thanks

Deepak

dpkm20@gmail.com

This was selected as the best answer
Deepak Maheshwari 7Deepak Maheshwari 7

Hi Shaik,

 

Hope the above solution works for you!
If not please let me know.

 

Thanks
Deepak

SHAIK MOHAMMAD YASEENSHAIK MOHAMMAD YASEEN
thanks Deepak Maheshwari 7,

It washelpful :)