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
LuciferLucifer 

Date methods ??

I'm trying to create a shedule job that sends email alerts 2 days befor due date. But some how list task near overdue doesn't let me save. It shows problem with the last "And" part( The highlighted part). Could somebody point me out where I am going wrong?  

 

 


List<Task> tasksNearOverdue =[SELECT Id, ActivityDate, Subject FROM Task WHERE WhatId IN :requestIds AND IsClosed = false AND :Date.today().addDays(-2) >= ActivityDate ] ;

Best Answer chosen by Admin (Salesforce Developers) 
vishal@forcevishal@force

Hi Lucifer,

 

In your query, you're starting your where clause with a method. your LHS of a condition should always be a field from the object and RHS should be a variable or a method.

 

I tried this, it works:

 

List<Task> lst = [SELECT Id, ActivityDate, Subject FROM Task WHERE IsClosed = false AND ActivityDate <= :Date.today().addDays(-2)];

Let me know if you have any questions.

All Answers

vishal@forcevishal@force

Hi Lucifer,

 

In your query, you're starting your where clause with a method. your LHS of a condition should always be a field from the object and RHS should be a variable or a method.

 

I tried this, it works:

 

List<Task> lst = [SELECT Id, ActivityDate, Subject FROM Task WHERE IsClosed = false AND ActivityDate <= :Date.today().addDays(-2)];

Let me know if you have any questions.

This was selected as the best answer
LuciferLucifer

Thanks Vishal.. You are such a life saver..

vishal@forcevishal@force

Glat to help. Anytime!