You need to sign in to do that
Don't have an account?

Need help with nested queries
I am new to salesforce SOQL and I seem to be having an issue when i try to use nested queries the query i am trying to perform is
List<Space__c> sp = [Select Name, Suite__c, (Select Name from Location__c), (Select Name from RecordType where Name = 'Commercial') from Space__c];
and i keep getting this error
Name, Suite__c, (Select Name from Location__c), (Select Name from
^
ERROR at Row:1:Column:42
Didn't understand relationship 'Location__c' 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.
even if i append __r instead of __c i still get the same issue any ideas will help i just need the names out of the 2 related objects
List<Space__c> sp = [Select Name, Suite__c, (Select Name from Location__c), (Select Name from RecordType where Name = 'Commercial') from Space__c];
and i keep getting this error
Name, Suite__c, (Select Name from Location__c), (Select Name from
^
ERROR at Row:1:Column:42
Didn't understand relationship 'Location__c' 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.
even if i append __r instead of __c i still get the same issue any ideas will help i just need the names out of the 2 related objects
Thanks,
Balayesu
All Answers
in nested query you have to use the child relationship name of the lookup field of that object.
for example,
Location is a lookup field of the object Space, just open the details of this lookup field and find the relationship name , suppose itit is "Locations", then your query is like,
List<Space__c> sp = [Select Name, Suite__c, (Select Name from Locations) from Space__c];
Mark it as the best Answer if it helps.
Thanks,
Balayesu
You have to provide the right name of your relationship object. There is an easy to find this.
Logon to https://workbench.developerforce.com/login.php
Click on the Info-->Standard & Custom Objects
Choose an object to describe: Choose your parent object Space__c here
Drill down to Child relationship folder-->Choose your child object name
Then make use of the value in the field relationshipName:
This will solve this error.
Select Name, Suite__c, (Select Name from Property_Name__r), RecordType from Space__c where RecordType.Name = 'Commercial'
ERROR at Row:1:Column:42
Didn't understand relationship 'Property_Name__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.
Note: Property_Name__c is the name of the custom lookup feild on space to location
also tried Child Relationship Name: Spaces
as this is what shows up when i open the custom feild
Thanks,
Balayesu
Property_Name is a field not the object name
select Id, Name, (select Name, Suite__c, RecordType.Name from Spaces__r) from Location__c where RecordType.Name = 'Commercial'