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
Dave StevensonDave Stevenson 

How to change field when Edit button clicked?

I added two custom fields to an object with history tracking, editStartTime and editStopTime. I want editStartTime to hold the time the 'Edit' (or 'New' or 'Clone') button was pressed for the object. When the 'Save' button is pressed, I can easily set editStopTime in an Apex trigger, but how do I get the editStartTime? 

The editStartTime will be cached in the object being edited, and will only be stored in the database if the edit is saved. If an edit is cancelled, the times will be discarded. I do not plan to display the start/stop fields on any page layout. Their values will only be visible in the field history section for a record.

I want the solution to work globally, both desktop and mobile, and from any page that has a 'Edit', 'Clone', 'New', or 'Save' button (I think that's all the standard buttons, did I miss any?) for this object.

I am new to salesforce, and my experience with other development environments gives me pre-conceived notions about how to do this that do not seem to match up with salesforce. I have been reading about custom buttons, controllers, page layouts, etc., and I should be able to follow the related tutorials. I'd like direction on which specific steps I should take to implement my requirements. For example:

Must I create a custom Edit button (and New, Clone), or is there a way to hook a small bit of code into the standard button, perhaps by customizing the controller?

If the start/stop values will only be displayed in the field history section, do I need to add or modify any page layouts?

Please list the steps of the simplest solution you would implement.

Thanks.
Dave StevensonDave Stevenson
Hmm, maybe as simple as:
1) a field update workflow rule to set editStartTime when a record is created, and any time it's edited
2) a trigger to set editStopTime on insert or update
Trying that now.
Dave StevensonDave Stevenson
That seemed to work. I had to select 'created, and every time it's edited' for the evaluation criteria, and for the rule criteria I selected 'formula evaluates to true' and simply used 'True' as the formula.
Dave StevensonDave Stevenson
Nope, on closer inspection, the start and stop times are identical. In my first tests, I created or edited an object and quickly saved it. In subsequent tests, I allowed more time to elapse between edit and save. The start time is always the same as the end time, so it must be that the workflow rule does not fire when you click 'Edit', but only when you click 'Save'. Is there a way to make the workflow rule fire when 'Edit', 'New' or 'Clone' is clicked, or must I abandon this approach?
Rama ChunduRama Chundu
I know this is very old thread, but have you been able to find any solution for this?