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
Sreenivas VSreenivas V 

how to query the relationship objects in soql?

SOQL to fetch the cases related to logged in users
Relationships: User - > service apartments -> work orders -> cases

SA (Parent) - work orders (child) - Cases (Parent to work orders)
NagendraNagendra (Salesforce Developers) 
Hi Sreenivas,

May I suggest you please check with below links on how to query the relationship objects in Salesforce.

Please tweak it as per your objects so that it can help you out. Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra
Prashant Pandey07Prashant Pandey07
Hi Sreenivas,

Correct me if I am worng the loggedin user's record mean owner of the reord right..if yes please try to execuite the below query in developer console.
 
/****Object and Fields API names
work order - work_order__c
Service Apartment - sa__c
case__c-Child relationship field on Work order

***/

list<work_order__c> wo = [select sa__c from work_order__c where sa__c in (select id from sa__c) ];
list<id> Accid = new list<id>();
for(work_order__c wonew:wo)
    accid.add(wonew.sa__c);//child reationship field to get the id of SA.

list<case> cas=[select id, from case where case__c in :accid and ownerid=OwnerId=:UserInfo.getUserID()];
system.debug(cas);

--
Thanks,
Prashant