+ Start a Discussion
Devendra Hirulkar 3Devendra Hirulkar 3 

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

hello friends
here i have write a trigger that copy data from parent obj to child when name is match
but in my trigger the following error shows (Didn't understand relationship 'Subscriptions__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 dont undestand the problem
so plese help me 
here is my trigger 

trigger copyproductnametoaccount on Subscription__c (after insert,after update) //You want it on update too, right?
{
  Map<ID, Account> parentpname = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (Subscription__c childObj : Trigger.new)
  {
    listIds.add(childObj.membership_type__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentpname = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID, membership_type__c FROM Subscriptions__r) FROM Account WHERE ID IN :listIds]);

  for (Subscription__c sub : Trigger.new)
  {
     Account myParentpname = parentpname.get(sub.membership_type__c);
     myParentpname.Product_Name__c = Decimal.valueOf(sub.membership_type__c);
  }
    
  update parentpname.values();
}

  
 
Sumitkumar_ShingaviSumitkumar_Shingavi
So it is saying Subscriptions__r is not right child relationship name. You can visit same lookup field and see child relationship name to verify or if you are using IDE (Eclipse / Force.com IDE) then you can see "Child Relations" and jump on that particular relationship you want.
Amit Chaudhary 8Amit Chaudhary 8
Just click on child object Name and then select the lookup field and check field child relationship name.

For Example :- On Contact we have a lookup field on account. click on Field Account Name. Then below screen will open
from below screen you can check "Child Relationship Name".

User-added image

Same thing you can check on your custom object.

Sample query with account and contact 

select id,name ,( select id,firstname,last from Contacts ) from account 

Hope this helps. If yes, mark it as solution so that it can help other's too who have same problem.

Thanks,
Amit Chaudhary
Devendra Hirulkar 3Devendra Hirulkar 3
hello
Sumitkumar and amit
in the above trigger the product field (membership_type__c ) is lookup to the subscription but still same error show
(Didn't understand relationship 'Subscriptions__r' in FROM part of query call) i think when we lookup the releationship is created  so what is problem
thanks,
devendra
Sumitkumar_ShingaviSumitkumar_Shingavi
Please follow the IDE path I have suggested and you can figure it out in a minute using that with Query required.
Amit Chaudhary 8Amit Chaudhary 8
Hi Devendra, 

Please check your Subscriptions__c object. On that object hope you have one Account lookup.
Click on that field and then check "Child Relationship Name".

Thanks,
Amit Chaudhary