Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
error

We made a wrong turn. Try again.

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

 
1 answer
  1. Dec 5, 2016, 12:14 PM
    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
0/9000