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
Dea73Dea73 

Why am i getting an error?? Please help!!!!

Below is a SOQL where i try to retrieve information from my parent object (in a master detail relationship) where circuits (master) is the parent and Work_on_Circuit is my child (detail).

 

The error i'm getting is :

junctionCircuits Compile Error: The inner select field 'Circuit__r.id' cannot have more than one level of relationships at line 16 column 38 

<script type="text/javascript">// var tabId = getCookie('dmTab'); var closeButtonId = 'thePage:theForm:closeButton'; if (tabId && getBottomPanelHeight() > 28) { showCloseButton(closeButtonId, true); } else { showCloseButton(closeButtonId, false); } function showHideControllerExtensionTabs() { var controllerTab = document.getElementById('thePage:theForm:controllerTab'); if (typeof(controllerTab) != 'undefined' && controllerTab !== null) { controllerTab.style.display = (false) ? 'inline' : 'none'; } document.getElementById('thePage:theForm:extensionTabGroup').style.display = (true) ? 'inline' : 'none'; } // </script>

 

[select Id, Name,Circuit_ID__c, Circuit_Status__c from Circuits__c where Id IN (select Circuit__r.id from Work_on_Circuit__c where Work_on_Circuit__c.Work_Order__c =: woid)]

 

How am i supposed to get the Id ??

Best Answer chosen by Admin (Salesforce Developers) 
*werewolf**werewolf*

Because you're referencing Circuit_r.Id in there, which is a field from a relationship.  Fortunately for you, it seems that all you actually need is the Id field, which is stored directly on the object in question.  So try instead using Circuit__c as your inner select:

 

select Circuit__c from Work_on_Circuit__c where Work_on_Circuit__c.Work_Order__c =: woid

All Answers

*werewolf**werewolf*

Because you're referencing Circuit_r.Id in there, which is a field from a relationship.  Fortunately for you, it seems that all you actually need is the Id field, which is stored directly on the object in question.  So try instead using Circuit__c as your inner select:

 

select Circuit__c from Work_on_Circuit__c where Work_on_Circuit__c.Work_Order__c =: woid

This was selected as the best answer
*werewolf**werewolf*

Oh but also something else is wrong with that inner select.  It'll complain about the extra reference to Work_on_Circuit__c in the where.  Should be:

 

select Circuit__c from Work_on_Circuit__c where Work_Order__c =: woid

Dea73Dea73

Thank you for your help werewolf!!

 

I changed my code and it's still not happy :smileymad:

Now it's giving me tthe following error:

Error: Invalid field Circuit__c for SObject Circuits__c 

 

I was thinking of doing a work around:

List<id>  ids = [select Circuit__c from Work_on_Circuit__c where Work_Order__c =: woid];

 

List<Circuits__c> circuits = [select Id, Name,Circuit_ID__c, Circuit_Status__c from Circuits__c where Id IN (ids)];
not sure how to code it :)

 

 

Dea73Dea73

Nevermind, it worked!! I just didn't have the same columns that i retrieved being displayed in my pageBlockTable.

 

Thank you so much for your help!!!