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
vishnu nvvishnu nv 

Manager List : SOQL Error

Hi,

I am trying to retrieve all the managers from the account with the below SOQL query.

SELECT Name FROM User WHERE ManagerId  IN (SELECT ManagerId  FROM User WHERE ManagerId !=NULL)

But i am facing error :
The inner and outer selects should not be on the same object type

Do we have any other alternatives ?
Best Answer chosen by vishnu nv
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Vishnu,

Can you try the below query and let me know if this work in your use case.
 
SELECT id, Name,Manager.name FROM User WHERE ManagerId !=null

You cannot query on the same object in a subquery as in the main query.Because of which you faced the above error.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Vishnu,

Can you try the below query and let me know if this work in your use case.
 
SELECT id, Name,Manager.name FROM User WHERE ManagerId !=null

You cannot query on the same object in a subquery as in the main query.Because of which you faced the above error.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
reinmi joereinmi joe
List of Governor Limits in Salesforce for Apex ... Salesforce shows an error and pauses the process that caused the error. TJ Maxx / TJX Credit Card Login (https://tractorsinfo.net/tj-maxx-tjx-credit-card-login/)