+ 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
Raveendra
 
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.

Thanks,

Manohar

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

Thanks 
Raveendra
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
Ravindra,
please try this,
select status, count(Id) from lead group by status

you may also refer
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_count.htm

please mark it as solved if it helps solving ur problem
AvaneeshAvaneesh
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
AvaneeshAvaneesh
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])
            {
                intCount+=(Integer)result.get('intVal');
            }

            System.debug('No of records are: '+intCount);
        }
    }
Source:
https://salesforce.stackexchange.com/questions/102193/need-to-count-more-than-50000-records-but-not-able-to-do-it-even-with-readonly-a

Thanks
D Naveen Rahul.