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

Trigger to Update Custom Field on Account after an Event Date/Time Passes


I'm trying to figure out how to write a trigger that will update a custom field (Stage_c) with a particular pick-list value after an Event date and time passes.

Basically in the Event Subject field, I have a picklist value called "Needs Assessment", what I need to accomplish is...if an Event has the subject of "Needs Assessment" and the date and time passes i.e., "Completed" and this Event now falls under Activity History, I need to have the custom field (Stage_c) update to a picklist value "Needs Assessment Completed".

I have triggers working great for the same process on Tasks, but since Events are not "Completed" per se, how do I go about writing a trigger for this same action but on events? Is it possible?

Below is the code I currently use on my Task trigger:

trigger changeAccountStagetask3 on Task (before update, after update) {
    List<Account> accsToUpdate = new List<Account>();
        for (Task tsk:{
            if(tsk.Status=='Completed' && tsk.Subject=='Initial Sell/Needs Assessment'){
                Account ld = new Account(Id=tsk.whatid);                             
                     ld.Stage__c = 'Needs Assessment Completed';
        update accsToUpdate;

Any help would be wonderful!!!

TC DeveloperTC Developer
Use a time dependent workflow which will update some flag fire your trigger when the field is changed