3

Issue:

Below is a part of my class for updating Activity Count fields. I want to only select the id's from closed Tasks and also closed Events. I have no clue why my two lists below give me the "Compile Error: expecting a colon, found 'system.now'":

List leadsWithClosedTasks = [select id,Lead_Activity_Count_Closed__c,(select id, Status from Tasks where Status = 'Completed'), (select id, EndDateTime from Events where EndDateTime >= system.now())from Lead where Id IN : Leadids];

List leadsWithClosedTasks = [select id,Lead_Activity_Count_Closed__c,(select id, Status from Tasks where Status = 'Completed'), (select id, EndDateTime from Events where EndDateTime >= system.now())from Lead where Id IN : Leadids];

What we need:

We need to select the just the id's of the "Closed" Tasks and ALSO "Closed" Events and also vice versa for Open Tasks and Events. Selecting Closed & Open Events is not working for some reason? Does anyone know how to do this?

Thank you ahead of time.

    //update all of the Leads with the number of Closed Tasks and Closed Events
    List<Lead> leadsWithClosedTasks = [select id,Lead_Activity_Count_Closed__c,
   (select id, Status from Tasks where Status = 'Completed'), (select id, EndDateTime 
   from Events where EndDateTime >= system.now())from 

    Lead where Id IN : Leadids];

    List<Lead> leadsUpdatableClosed = new List<Lead>();

    for(Lead Lclosed : leadsWithClosedTasks){

    Lclosed.Lead_Activity_Count_Closed__c = Lclosed.Tasks.size();
    leadsUpdatableClosed.add(Lclosed);

    }

    if(leadsUpdatableClosed.size()>0){
    update leadsUpdatableClosed;
    }


    //update all of the Leads with the number of Open Tasks and Open Events
    List<Lead> leadsWithOpenTasks = [select id,Lead_Activity_Count_Closed__c,
    (select id, Status from Tasks where Status != 'Completed'),(select id, EndDateTime 
    from Events where EndDateTime < system.now()) from 

    Lead where Id IN : Leadids];

    List<Lead> leadsUpdatableOpen = new List<Lead>();

    for(Lead Lopen : leadsWithOpenTasks){

    Lopen.Lead_Activity_Count_Open__c = Lopen.Tasks.size();
    leadsUpdatableOpen.add(Lopen);



    if(leadsUpdatableOpen.size()>0){
    update leadsUpdatableOpen;
    }

Thank you everyone.

1 Answer 1

3

You're trying to bind a system function inside a query, so it should be:

EndDateTime >= :System.now()

You could also use the date literal:

EndDateTime >= TODAY

But this is semantically different (it starts at 12:00:00 AM instead of the current instance in time).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .