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
Deepika GhoseDeepika Ghose 

SOQL Query to count record types

SOQL query to count the no of record types present in a page
Shiva RajendranShiva Rajendran
Hi Deepika ,

One simple solution to it is

List<AggregateResult> ag= [SELECT count(Id) tc, RecordTypeId   FROM Static_Data__c group by RecordTypeId];
for(AggregateResult ag:ags)
    System.debug(ag.get('RecordTypeId') +' '+ ag.get('tc'));

Replace Static_Data__c by ur object name . Let me know if you face any problems

Thanks and Regards,
Shiva RV
Shiva RajendranShiva Rajendran
Also if you want to know the count based on names alone then

List<AggregateResult> ags = [SELECT count(Id) tc,RecordType.Name recName   FROM Static_Data__c group by RecordType.Name ];
for(AggregateResult ag:ags)
    System.debug(ag.get('recName') +' '+ ag.get('tc'));

This will give the same answer with recordType name  and count result

Thanks and Regards,
Shiva RV