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
PzyrenPzyren 

Custom Date fields on Event and Task

I am attempting to create my own custom date fields to use with events and tasks. When my method is called, it should determine whether it is an event or task and use some logic to set the date. I will be using this method in a query to filter my table. for example

String qry = select [datefilter(event, allOpen), status from Task]; 

 I'm hoping this will return all open tasks/events. Pretty much same plan for all other picklist values

 

Here is the picklist which is inside a list called dateList

   All Open

   All Past 

   Next 7 days.

 

Anyone know how I can go about this? potentially using Date methods? Thanks for your time

 

public void datefilter(String taskOrEvent, string date){

 if (taskOrEvent =='task' && date = 'allOpen'){
   //do logic
   }

  if (taskOrEvent =='task' && date = 'all past'){
   //do logic
   }

if (taskOrEvent =='task' && date = 'Next 7 days'){
   //do logic
   }

 if (taskOrEvent =='event' && date = 'allOpen'){
   //do logic
   }

  if (taskOrEvent =='event' && date = 'all past'){
   //do logic
   }

if (taskOrEvent =='event' && date = 'Next 7 days'){
   //do logic
   }

}

 

Best Answer chosen by Admin (Salesforce Developers) 
levaleva

All Past         ->  Some_Date_Var__c  <  Date.today() 

Next 7 days  ->  Some_Date_Var__c >= Date.today().addDays(7)

All Open , that would depend on how you define open