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
Ravindra reddy MRavindra reddy M 

How to query the count of lead status

HI All,
 I have an object that is lead one in that I need to count the lead picklist values. let say we have 100 records in the lead , 10 records status are lead = open, another 10 are closed like this I need to display using soql.

Thanks & Regards
Manohar kumarManohar kumar

Hi Ravindra,

In the soql you just query select id , name from lead where Status = 'Open'

And in the vf page, make a pageBlock table and you can show those records. i am not sure if this is what you are asking.

Please let me know if this helps.



Ravindra reddy MRavindra reddy M
Hi Manohar Kumar,
I need to count the status field values 

Pavit SiddhuPavit Siddhu
Hello. r u want to count status!=null
select id , name, count(status) from lead where Status != null
Malni Chandrasekaran 2Malni Chandrasekaran 2
please try this,
select status, count(Id) from lead group by status

you may also refer

please mark it as solved if it helps solving ur problem
Hi Ravindra 

if you want to use Soql Query to find Status of Lead so Status picklist have four Default values they are....
Open - Not Contacted
Working - Contacted
Closed - Converted
Closed - Not Converted 

so your Query would depend picklist value

select id, name,status from lead where status='Open - Not Contacted' OR  status='Closed - Not Converted'

if this would helpful marked as best answer 
Thank you 
Avaneesh Singh
buggs sfdcbuggs sfdc
hey ravinder,

There is no partiular soql query for that, try to select id , name from lead where Status = 'Open' in the following way, it will give you the total Query Results on you can count in that way,check below screenshot fy!

count the total rows
Hii Ravinder 
select  count(status) from lead where status='Open - Not Contacted' OR status='Closed - Not Converted'
check this Query result

Thank you 
Avaneesh singh
Naveen Rahul 26Naveen Rahul 26
Hello Ravindar ,

you can use below query to get the total no of recorrds using below query.Also system.Limit exception will be thrown
if you have more than 5000 records
Integer leadtotal=[select count() from lead where Status = 'Open'];
So use below code to get the total count.
public class Test_Aggregate{
        public static void TestAgg() {
            Integer intCount = 0;

            for(AggregateResult result :[SELECT COUNT(Id) intVal FROM Custom_Object__c])

            System.debug('No of records are: '+intCount);

D Naveen Rahul.