+ Start a Discussion
Praveen Kumar 160Praveen Kumar 160 

Didn't understand relationship 'Case__r' in FROM part of query call.

Contact is parent and Case is child and am trying to run the following query.
Contact__c c=[Select Id, Name, (select Name from Case__r ) from Contact__c];

but query is gving me below error.

Didn't understand relationship 'Case__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.

i tried same kind of query for my another app it's working. y not here? errrrrrrrrrrrrrrrrr
Best Answer chosen by Praveen Kumar 160
Suneel#8Suneel#8
I guess you are looking for Contacts along with their case information.Below is the SOQL for that.Both are standard objects so you don't need to give __r after the relationship name.

List<Contact> contactList=[Select Id, Name, (select id from Cases ) from Contact];

Please read below links for more information regarding relationship queries

https://developer.salesforce.com/page/From_SQL_to_SOQL
https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com

All Answers

Suneel#8Suneel#8
I guess you are looking for Contacts along with their case information.Below is the SOQL for that.Both are standard objects so you don't need to give __r after the relationship name.

List<Contact> contactList=[Select Id, Name, (select id from Cases ) from Contact];

Please read below links for more information regarding relationship queries

https://developer.salesforce.com/page/From_SQL_to_SOQL
https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com
This was selected as the best answer
Praveen Kumar 160Praveen Kumar 160
Thanks for your reply.

I am confused where __c and __r are exceptional.
and a lot confusion is that where to use plurals and singulars for object names.
please help me out
Suneel#8Suneel#8
You don't have to use __c and __r for any standard object and relationship.These are called relationship queries.You need to provide relationship name if you need pull data from another object along with the one object.If related object is a custom object then you need to give the relationship name like MyCustomRelationship__r to access it.If it is standard just a relationship name.And __c follows for all custome objects.You can read the link I referred to get more information
11c-at-sfdc11c-at-sfdc
I have tried to explain the mystery of __c and __r as they relate to relationships and the roles they play in accessing fields of the parent objects for a given child object as well as accessing the fields of the child objects for a given parent object. http://11concepts.com/sfdc/blog/understanding-__c-and-__r/ 
Hope this helps! 
vikrant padole 12vikrant padole 12

Case parent and Loan Applicationis child and am trying to run the following query.
public static List<Case> getCase(String agencyCode,string status,string userId)
    {
        List<Case> caseLists = new List<Case>();
       system.debug('Inside getCase()');
       caseLists = [SELECT Id,CaseNumber,Business_Unit__c,FCO_Note__c,Sub_Status__c,Agency__r.Name,Agency__r.External_Code__c,Verifier__r.Name,Reviewer__r.Name,
                                SCHEME_NAME__c,SCHEME_ID__c,Applicant__r.Office_Address__c,Status__c
                                FROM Case where Agency__r.name =:agencyCode and Status=:status and Owner.Id = :userId ];
List<Applicant__c> applicantDetails = new List<Applicant__c>();
applicantDetails = [select (select Id,CaseNumber,Business_Unit__c,FCO_Note__c,Sub_Status__c,Agency__r.Name,Agency__r.External_Code__c,Verifier__r.Name,Reviewer__r.Name,
                                SCHEME_NAME__c,SCHEME_ID__c,Applicant__r.Office_Address__c,Status__c
                                FROM Case where Agency__r.name =:agencyCode and Status=:status and Owner.Id = :userId and RecordType.DeveloperName =: IFB_ALL_GlobalConstants.CASE_RECORDTYPE_MBLPDV ORDER BY CreatedDate DESC),
                            (select Type__c,Line_1__c,Line_2__c,Line_3__c,Landmark__c,Pincode__c,State__c,City__c from Addresses__r where Type__c in(:GlobalConstants.ADDRESS_TYPE_OFFICE_ADDRESS,:GlobalConstants.ADDRESS_TYPE_RESIDENCE_ADDRESS ))
                            from Applicant__c 
                            WHERE case__r IN : loanApplicationIds and Type__c = : GlobalConstants.APPLICANT_TYPE_APPLICANT];

Error:
The error which I am getting is "Variable does not exit" for loanapplicationId