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
Radha Rathinavel PandianRadha Rathinavel Pandian 

How to find the size of parent lookup query

My Parent is : raddescription
My Child is : Case

I need to need to find the size of parent query(raddesciption). I have tried
select CaseNumber,(select count(id) from rad_Descriptions__r) from Case

I got "only root queries support aggregate expressions". Please help me to find the size
Waqar Hussain SFWaqar Hussain SF
list<Case> Cases = [select CaseNumber,(select count(id) from rad_Descriptions__r) from Case];

list<CaseWrapper> csw = new  list<CaseWrapper>();
for(Case c : Cases){
CaseWrapper cw = new CaseWrapper();
cw.cs = c;
cw.totalRadDisc =  c.rad_Descriptions__r.size();
csw.add(cw);
}



public class CaseWrapper{
public case cs {get; set;}
public integer totalRadDisc {get; set;}
}

You can use wrapper class for that. See example above