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
Mel LisauMel Lisau 

Why am i getting "Didn't understand relationship" in my SOQL call ?


I have a SOQL call as follows:
select Account.AccountNumber, Account.AccountSource, Account.Active__c, Account.AnnualRevenue, Account.BillingAddress,
Account.CreatedById, Account.CreatedDate, Account.CustomerPriority__c,
Account.Name, Account.NumberOfEmployees, Account.NumberofLocations__c, Account.OwnerId, Account.Ownership, 
 Account.Site, Account.SLA__c, Account.SLAExpirationDate__c, Account.SLASerialNumber__c,
 Account.SystemModstamp, Account.TickerSymbol, Account.Tradestyle, Account.Type, Account.UpsellOpportunity__c, 
   (select Sequence__c, Action__c from AcmeCo_Account_c__r where Processed__c = false and IDM__c = 'TEST1' ) 
from Account where Account.Id in (select Link__c from AcmeCo_Account__c where IDM__c = 'TEST1' and Processed__c = false) 

But it give an error:
(select Sequence__c, Action__c from AcmeCo_Account_c__r where Processed__c
                                    ^
ERROR at Row:17:Column:40
Didn't understand relationship 'AcmeCo_Account_c__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. 

The custom table is created . 
How can i avoid this or correct the query ?

thanks

 
Best Answer chosen by Mel Lisau
RituSharmaRituSharma
You may check in WSDL(Setup->API->Generate Enterprise WSDL->Generate).  Search for <complexType name="Account"> text and then look for the exact relationship name.

All Answers

RituSharmaRituSharma
Replace AcmeCo_Account_c__r with AcmeCo_Account__r. If it does not work, then see the schema to check the exact relationship name.
Mel LisauMel Lisau
same error 

(select Sequence__c, Action__c from AcmeCo_Account__r  where Processed__c
                                    ^
ERROR at Row:17:Column:40
Didn't understand relationship 'AcmeCo_Account__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.

Now i assume i check the schema of Account ?
Mel LisauMel Lisau
Also , how do i exacxtly check the schema for the name ? Sorry im a bit new to all of the SOQL and IDE of Salesforce . thanks
RituSharmaRituSharma
You may check in WSDL(Setup->API->Generate Enterprise WSDL->Generate).  Search for <complexType name="Account"> text and then look for the exact relationship name.
This was selected as the best answer
Mel LisauMel Lisau
Oh thanyou so much it was actually AcmeCo_Accountc__r  NOT AcmeCo_Account_c__r.
These relationships are created by the user who creates the .net app ie to register classes etc ?
Mel LisauMel Lisau
But in my code the relationship name is expliciitly AcmeCo_Account_c__r is there a reaso it has been changed to AcmeCo_Accountc__r ?
RituSharmaRituSharma
__c is used for objects and __r is for relationships.
Mel LisauMel Lisau
So if i was to create lets say a relationship test__c__r  , when i regsister with Salesforce , does it remove the __ before the c and make it test__r ?
It is actually AcmeCo_Account_c__r  (single _ before the c) ?  Thats whats a bit confusing
RituSharmaRituSharma
You can't create relationship with __c or __r. We can just specify the relationship name(e.g. AcmeCo_Account) and salesforce automatically appends __r to it.
Mel LisauMel Lisau
I get that but if you lookat mine i created AcmeCo_Account_c    <=== only a single underscore , so Salesforce should append __r after that hence i get AcmeCo_Account_c__r , but it looks like it doesnt like single '_' as well ?
RituSharmaRituSharma
May be, I really can't say that. But anytime you may refer the WSDL to see the exact name.
Mel LisauMel Lisau
ok i think i will not use the _c for the relationship name as it may cause an error and stick to what you suggested. 
I cant keep  referring  to the WSDL because I generate SOQL queries and try to run them and hence it errors becuase its the wrong relationship name in the query.  
But thankyou for the help
RituSharmaRituSharma
Happy to help you. Please mark my answer as the best answer so that it's helpful for others in future.