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
Bharat.SharmaBharat.Sharma 

Stuck in SOQL query in Lead Object

Hello all,

Thanks in advance,

I am trying to fetch some records in object LEAD. but i am stuck, please Help me to Out of there.

Lead object have a standerd field LastActivityDate, In some leads it is blank and some times it is filled with a specific date. so i want  Count the leads that contains value (Date) in their LastActivityDate(Field) and count too who doesn't have value of LastActivityDate(field) means (LastActivityDate = null) .i want these two record in one table.

I have already impliment that scenario, But

i have two query first one is returning null values :  
SELECT COUNT(id)  FROM Lead WHERE LastActivityDate = Null

Secoend one is returning not null values:
SELECT COUNT(id)  FROM Lead WHERE LastActivityDate != Null


Acctully i am creating dashboard in VF page thats why i need a query who calculate the LastActivityDate null and not null values and show them in a pie chart so please use  GROUP BY LastActivityDate .


Thanks and Regards
Bharat Sharma

 
Ajay K DubediAjay K Dubedi
Hi Bharat,
I think that you are not using the correct return type for the query that you have written. If you want to use Count(Id), then you should use the following query ->
AggregateResult[] groupedResults = [SELECT Count(Id)idc FROM Lead WHERE LastActivityDate = Null];
Object countid = groupedResults[0].get('idc');
Where 'countid' will return the number of Leads where the value of 'LastActivityDate' field is null.

And if you want an Integer return type, then use this simple query ->
Integer j = [SELECT Count() FROM Lead WHERE LastActivityDate != Null];
Where 'j' will return the number of Leads where the value of 'LastActivityDate' is not null;

Regards,
Ajay