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
Wasim AkramWasim Akram 

get class name and student count using aggregate query salesforce

Best Answer chosen by Wasim Akram
Alexander TsitsuraAlexander Tsitsura
Maybe you need this
SELECT Count(ID) studentCnt, Class__r.Name className FROM Student__c GROUP BY Class__r.Name

Thanks, Alex

All Answers

Alexander TsitsuraAlexander Tsitsura
Hi Wasim,

You need use Group By for this
SELECT Count(ID), Name FROM Student__c GROUP BY Name

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
 
Wasim AkramWasim Akram
Class And Student Are 2 Objects
Alexander TsitsuraAlexander Tsitsura
Maybe you need this
SELECT Count(ID) studentCnt, Class__r.Name className FROM Student__c GROUP BY Class__r.Name

Thanks, Alex
This was selected as the best answer