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 on Task Edit Button-Click Event



Is it possible to fire an Apex trigger on a Task sObj when a user clicks the Edit button?   I'd like to be able to have a trigger automatically put the date ( in The Task's Description field.   Right now my trigger event is defined as "before insert", but this won't update the Task.Description field until after the Task Save button is clicked.   That's too late :)


Any ideas??   Thanks as always for your collective support.


Best regards,



You can override the standard salesforce buttons.


Create a custom VisualForce/Apex Controller which overrides the Edit button. Then update the task record with the system date before you call the SAVE or UPDATE in your custom controller. This will allow you to update it before it hits the trigger.


 Hi Cory,


Thanks very much for the direction.   I went down this path as suggested and it works great with one hitch - I've lost the original Edit behavior.   In other words, I can now update my fields via the new Edit button controller, but I can't get into the default Edit mode for manually typing in additional comments after the programmatic update.  


This is the exact behavior I'm after at this point:


How can one programmatically put the controller into the default edit mode either from either the Visualforce page script or the controller extension?


Thanks again!!



You can instantiate a standard controller, set it to edit mode, and return that view in your edit override. Kinda like below.


public class ExampleController
ApexPages.StandardController stdController;

public ExampleController(ApexPages.StandardController ctl)
        stdController = ctl;

public PageReference executeAction()
    Account acct = (Account) stdController.getRecord();
    acccount.Activation_Date__c =;

    stdController = new ApexPages.StandardController(account);
    return stdController.edit();



Brilliant…almost there!  The crux now is getting the (using your example syntax) executeAction() method to fire.    I had originally put my update metod call into the Visualforce page’s “action” property as in:


                <apex:page standardcontroller="Task" extensions="VFTaskButtonOveride" action=”{!executeAction}”>


Can you guess what this lead to?  Yep, upon return of the page reference from the controller we entered into an infinite loop.  


From the docs, I’m just not seeing an obvious way to access this method without adding a custom button or link.    What do you think??


Thanks a million.  


Wow...this is incredibly frustrating.   I was hoping I could work around this using a second VF page that didn't have the action attribute set , but no go.   If you ask me, it's pretty ridiculous that we can't seem to set the detail on the VF page so we're in edit mode.  


Licking my wounds...


I found this cool way of firing trigger from custom button...


Cretae a checkbox field on the object.


On the button set this field to true.

and hide it on the page layout of the object.


fire a trigger when this field becomes true  and reset the field to false on the trigger.


Works for me!  :)



RiPaulRiPaul you hide your boolean flag this way?   How in the world did you think of that?!   I'll give it a go and in the meantime, thanks very much for taking the time to share your experience.