I need to know if an opportunity or Lead has any pending or Overdue tasks?
I can search for opportunity or Lead in WhatId of task and get all the records for this ID. How do i know if a task is overdue or pending? Which field should i refer on task to identify this
Thanks
Attribution to: Prady
Possible Suggestion/Solution #1
Are you trying to query these records using soql? if so the query would be something like
List<Task> leadOverdueTasks = [SELECT Id, ActivityDate FROM Task WHERE WhatId IN :leadIds AND ActivityDate <= :Date.today()];
The important thing being you are searching for a Due Date (api name for due date is ActivityDate) before or on today.
Edit
Logic for pending tasks: WHERE IsClosed = false AND currentdate <= ActivityDate
Logic for overdue tasks: WHERE IsClosed = false AND currentdate > ActivityDate
Attribution to: Daniel Blackhall
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3598