3

I am getting below error.

Didn't understand relationship 'Invoice_CU__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.

SOQL:

select Actuals__c,(select id,Total_Price__c from Invoice_CU__r) from Sales_Quota__c
  1. Sales_Quota__c(master)
  2. Invoice_CU__c (child) has lookup relationship.
3
  • 1
    check this post salesforce.stackexchange.com/a/128881/18731 use describe call to check correct relationship name and use that
    – Ratan Paul
    Jul 7, 2016 at 9:59
  • 1
    Or else refer to your wsdl to get the correct relationship name. It needs the plural form of child here, probably with s at the end.
    – highfive
    Jul 7, 2016 at 10:06
  • 1
    Super @Ratan I used below code to get relationship.I was able to figure it out. Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe(); for (Schema.ChildRelationship cr: R.getChildRelationships()) { system.debug('====child object==='+cr.getRelationshipName()); } Correct SOQL will be : select Id,Actuals__c,(select Id,Total_Price__c from Invoices__r) from Sales_Quota__c
    – Jack vardy
    Jul 7, 2016 at 10:06

2 Answers 2

5

Get All Child objects relationship name.

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
for (Schema.ChildRelationship cr: R.getChildRelationships()) 
{
  system.debug('====child object==='+cr.getRelationshipName());
}

Try to run above describe call in developer console and check the debug log and check the correct relationship name for Invoice_CU__c object and use it in your soql.

4

Run this code in developer console and you will get the Child relationship's API Name

for (ChildRelationship relationship : SObjectType.Sales_Quota__c.getChildRelationships())
    if (relationship.getChildSObject() == Invoice_CU__c.sObjectType)
        system.debug(relationship.getRelationshipName());

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .