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
EPSWDEVEPSWDEV 

Relationship Queries for Lookup Relationships

I wanted to know if I can use relationship queries to fetch data linked using lookup relationships ? I examples givein the doc talk about parent-child relationships but not of lookups.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf

A lookup is by definition a parent-child relationship.  The object that has the lookup field is the child.  So for example, Contact looks up to Account, therefore Contact is the child and Account is the parent in that case.

 

You can use a parent relationship's field inline in your query to look up from a child.  To look up children from the parent you can use a subquery.  Examples of both are given here:

 

http://www.salesforce.com//us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm#kanchor419