You cannt able to get it single SOQL query .. You will get The inner and outer selects should not be on the same object type error ..
use this code
Set<Id> parentId = new Map<Id, AggregateResult>([SELECT ParentId Id FROM Account WHERE ParentId != NULL GROUP BY ParentId]).keySet();
List<Account> acc = [select id from account where id not in : parentid];
Or
Set<Id> parentId = new Set<Id>();
for(AggregateResult a : [select parentid p from account group by parentid])
{
if(a.get('p') != NULL)
{
parentId.add((Id)a.get('p'));
}
}
List<Account> acc = [select id from account where id not in : parentid];
Thanks a lot . But I need to get the childs of Account , on which Account page i am currently on.So I need to fetch the Id from that account and then using that id I need to Fetch.
Use this code to fetch All child's according to your requirement
please mark the best answer if it helps you.
Thanks
Akshay
All Answers
The inner and outer selects should not be on the same object type error ..
use this code
Or
Thanks a lot . But I need to get the childs of Account , on which Account page i am currently on.So I need to fetch the Id from that account and then using that id I need to Fetch.
Use this code to fetch All child's according to your requirement
please mark the best answer if it helps you.
Thanks
Akshay