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
learn_sfdclearn_sfdc 

how to identify relationship between two objects

Hi,

How to get query and relationship between two objects(standard and custom)

i have below details

standard object - case
custom object - product version

 TESTCase = [Select  
                           c.AccountId, 
                            c.Account.Type,
                            c.RecordTypeId
        from Case c where Id= :ViewingCase.Id];

how do i include product version object fields in to above query.

Thanks
                   
                           
                          
                       
                   
Balayesu ChilakalapudiBalayesu Chilakalapudi
Try like this,
TESTCase = [Select  c.AccountId, c.Account.Type, c.RecordTypeId,(select Id From productversion__r) from Case c where Id= :ViewingCase.Id];
Let us know if it helps.
learn_sfdclearn_sfdc
Hi,

It does'n work... its throwing error - Compile Error: Didn't understand relationship
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Sj_dev, Basic Examples of SOQL RELATIONSHIPS:

Child > Parent (Standard Object)
Selectid,Account.Name,Account.Phone,Account.industry,Account.Type,Account.Rating,Account.website,Account.Ownership,Account.AnnualRevenue,Account.NumberOfEmployees,Account.CleanStatus from Contact

Child >Parent(Custom Object)

Selectid,COLLEGE__r.Name,COLLEGE__r.Contact__c,COLLEGE__r.Count__c,COLLEGE__r.Highest_Marks__c,COLLEGE__r.Address__cfrom Studnt__c

Parent >Child(Standard object)

select Name, Industry, (select AssistantName, Email from contacts)from ACCOUNT

Parent >Child (Custom Object)
1select id,Name,
(select Studnt__c.name__c from Studnts__r) from College__C

I hope it will be helpful.

BestRegards
RahulKumar
Balayesu ChilakalapudiBalayesu Chilakalapudi
I assumed the child relationship of your case is productversion__r.

go to fields of case and find Productversion lookup field and open its definition and find child relationship name. and append __r at the end of it and use this name instead of productversion__r
learn_sfdclearn_sfdc
Hi,

Case is a child of productversion. 

in case object i have a field productversion_test and its linked as lookup to product version
Balayesu ChilakalapudiBalayesu Chilakalapudi
Try like this,
List<ProductVersion__c> pvlist=[Select Id,(select AccountId, AccountType, RecordTypeId from cases where id=:viewingCase.Id) from productversion__c];
List<Case> caselist=new List<Case>();
for(ProductVersion__c p:pvlist){
     for(Case c:p.cases){
       caselist.add(c);
      }
}
Case testCase=caselist.get(0);