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
Maria Alexandra AndricaMaria Alexandra Andrica 

help to read relationship

I have the following relationshio between objects:
- Vehicle and Vehicle_location are in Master-Detail relationshiop
- Vehicle_location and Production_Location are in Look-up relationshiop

How can I link them in a soql query?
Rahul.MishraRahul.Mishra
Hi Maria:
 
Assuming object relationships are:

 Vehicle_location  (Parent)
 Vehicle (Child)
  Relationship : MD


  Vehicle_location  (Parent)
  Production_Location  (Child)
  Relationship : Lookup 

    

if above is correct then you can query the following way to query the parent and it's related child:

Select Id, Name,(Select Id, Name, Vehicle_location__c From Vehicle__r),(Select Id, Name, Vehicle_location__c From Production_Location__r) From Vehicle_location;
Mark solved if it does help you
Maria Alexandra AndricaMaria Alexandra Andrica
Not working
Select Id, Name,(Select Id From Vehicle__r),(Select Id, Name From
                                ^
ERROR at Row:1:Column:33
Didn't understand relationship 'Vehicle__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.
Rahul.MishraRahul.Mishra
Hi Maria,

Please populate the correct relationship name of your object, for custom object mostly it is : objectName__r
Chandra@AtlantaChandra@Atlanta
Marla,

please use the below query

select name, vehicle_location__r.name,  vehicle_location__r.vehicle__r.name
from
Production_location__c

by Falcon100 (if this was helpful, please provide feedback)