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

Soql query error - Didn't understand relationship

Hi All,

I have 2 custom object Invoicing and Invoice details. Invoice details has a lookup relationship to Invoice. this query works fine
[select Date__c,company__c  from invoicing_details_gen__c where invoicing__c=:invoiceId ];

but i need to query 1 field from invoicing__C object also. when i try this I get the below error:

Error: Compile Error: Didn't understand relationship 'Invoiving__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
[select Date__c,company__c ,(select region__c from invoicing__c) from invoicing_details_gen__c where invoicing__c=:invoiceId ];
How can i query this?

Head In CloudHead In Cloud

Hi Richa,

You can not use the parent object inside an inner query. Instead you can try this:

[select Date__c,company__c , invoicing__r.region__c from invoicing_details_gen__c where invoicing__c=:invoiceId ];


Hi - when i used this, I get the result for invoicing region as "[object Object]" instead of value. 
FYI: region is lookup to another table wher we maintian all country ans region.
Head In CloudHead In Cloud

You can try this :

[Select Id, region__c, (select Date__c, company__c  from invoicing_details_gen__r) from invoicing__c where id=: invoiceId];

Gyanender SinghGyanender Singh
Hi Richa

Here (select region__c from invoicing__c) in place of invoicing__c use the custom child relationship name of this field and after that your query will be fine.

Mirketa Software Pvt. Ltd.