3

I have custom objects called 'Project' and 'Status Report'. Project is a parent and Status report is child in a master detail relation ship.

With in trigger i wrote below query and getting the below error.

List<Project__c> lstP= [Select id,name,(select id,Name from Status_Report__c order by createdDate ASC limit 1) from Project__c where id in: projectIds];

ERROR at Row:1:Column:55 Didn't understand relationship 'Status_Report__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.

I tried the query by appending __r at the end of Status_report__c but still getting the error.

ERROR at Row:1:Column:55 Didn't understand relationship 'Status_Report__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.

Please let me know if have made any mistake.

  • 4
    Look at the field in SF. Look at the Child Relationship Name. That is what you need to be using with the __r appended – Eric Nov 28 '15 at 20:10
5

In setup click go to the child object and then click on the master-detail relationship field to Project and you will see the child-relationship name that should be used in the subquery.

Example from the docs:

SELECT LastName__c,
  (
    SELECT LastName__c
    FROM Daughters__r
  )
FROM Mother__c

Where Mother is the Parent object and Daughter is the child object.

  • 1
    The rule of thumb is that plural 's' and '__r' will be appended. The 's' part is what usually confuses a lot of people. – dzh Nov 28 '15 at 22:51
  • 2
    @dzh I just don't like to assume it's the plural because it isn't always the case, better off just looking it up. Like merchandise for example or someone deciding to make it something else for whatever reason. – Jenny B Nov 28 '15 at 23:47

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.