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
FTeohFTeoh 

Trigger to update checkbox based on date set by user

Hi, I am new to triggers and would love some help. I have 2 fields which are:
  • End Date (date field)
  • Active (checkbox)
What we are trying to do it is to create a trigger that would update the Active checkbox based on the End Date the user has provided.
E.g. when End Date = 15 September 2015, on that day itself, update the Active flag to FALSE.

Is this possible?
James LoghryJames Loghry
The best way to do this isn't an Apex trigger, but rather one of two choices:
  1. Use a formula field of type checkbox that returns true when today's date is >= the end date
  2. Use a process to execute a schedule action and a record update, to update a checkbox on the record.
Good luck!
Fabien LecoqFabien Lecoq
Hi, I would probably answer this requirement by coding in Apex a batch. Though you may be able to solve the issue by creating a time-based action associated to a workflow that trigger when your end date is modified. This time-based action should execute on that actual date. I haven't done that in the past but I think it should work.
Kannan N 10Kannan N 10
Trigger will not work in this case.   Trigger is to take an action, when the record is modified - but, in your case, this will be a future dated activity. If the information is not critical and require to be reflected immediately, setup a batch process records.   Formula is an alternative - however, try to keep the formula to a reasonably manageable level (no thumb rule, but ~ 5 to 10 per object) to reduce overheads.   Here is a quick way to do it using formula option.
Formula field to control activity status based on date value

formula value:   IF( End_Date_Test__c >= TODAY(),true,false)   (You may want to take care of negative conditions, such as null date value, if the field is not mandatory)