0
select id,name,Number_of_Subscriptions__c,(Select id from Subscriptions) from Contract

In the above scenario, Contract is parent object and Subscription is child object having lookup relationship.

The child-relationship name is "Subscriptions". But i am trying to execute above query it showing me error:

ERROR at Row:1:Column:54
Didn't understand relationship 'Subscriptions' 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 using __r also:

select id,name,Number_of_Subscriptions__c,(Select id from Subscriptions__r) from Contract

doesn't worked out!!

Any kind of help is appreciated!!

1

On the assumption that you have a custom object, Subscription__c, and that the Subscription__c has a (possibly master detail child) lookup field that references Contract, the important details are provided in the lookup field. For example, I have a "Shift_Break__c" custom object that has a lookup to "Shift__c". The field details are as follows:

enter image description here

It is the value of "Child Relationship Name", plus the "__r" suffix (so here Shift_Breaks__r) since this is a custom relationship, that must be applied in the nested SELECT.

Also look out for whether you are trying to reference a relationship from a different package (namespace) compared to where the query is being executed - in this context you'll need to prefix the relationship name with the package's namespace.

| improve this answer | |
  • Hi Phil, I used the relationship name only in my query then also it is throwing me error. – situ Feb 6 at 9:09
0

I have used relationship name only in my nested SOQL query:

enter image description here

enter image description here

| improve this answer | |
  • Is the "Contract" you are querying the same one that has this lookup field? If you click on the "Lookup Options" section's "Related To" link ("Contract") does this take you to a Salesforce "Contract" object, or is it a custom one? If it is a custom object, your query needs to do "... FROM Contract__c". – Phil W Feb 6 at 10:38
  • It is taking me to the same Contract object when i clicked on Contract Link from 'Lookup option' section. – situ Feb 6 at 10:47
  • OK, and is this custom or some Salesforce object? If it is custom, you have to have the "__c" suffix on the object type name in your query. – Phil W Feb 6 at 11:29
  • 1
    This should be an edit to your question, rather than an answer, I think. – Derek F Feb 6 at 12:14
  • 1
    Looks like subscription might be part of a managed package? In that case, you'll likely need to append the namespace to the beginning of the relationship, like MyNamespace__Subscriptions__r – Brian Miller Feb 6 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.