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

Update page layout/record type at specific date & time

I'm having a hard time getting my brain around a new trigger I'm trying to write:


Business Case: Users add Weekly Notes (a custom child object to Opportunities) records to Opportunities every week ahead of a weekly meeting on Tuesdays.  The users should not be able to revise their notes after the meeting, but should have to log a new record.  Note: I have a custom formula date field that identifies the next Tuesday's date from the Created Date.


Issue: I want to lock a record from editing after a specific date and time: local midnight before Tuesday's meeting.  This also needs to happen with no action on a user's part to trigger the update.


Ideas on how to handle this?  I already have one formula field to calculate the date of the next Tuesday meeting, and I have located a simple trigger to identify a user's local midnight here.




Just so I understand, you want to prevent anyone from editing/updating your custom child object (Weekly Notes) entry after a specific date/time.


Can't you just use validation rules and have it fire off with an error message whenever your condition is met (i.e. use the NOW() value and use appropriate conversion to  compare that to your formula date field and the midnight time)?
This will prevent anyone from doing any kind of update on any Weekly Note entry that meets the criteria.


I have a similar requiremnet.


I want to lock the whole record from being edited after the on click event of another custom buttom. Any suggestions please?


This is a floating date and time.  Ideally, I want the records to change page layout to a read-only page layout when Now() = the Monday before the next meeting, at midnight, user's local time.


Can I do a validation where if NOW() > (Tuesday's meeting date at midnight between Monday/Tuesday local-time)?  If so, I have a few more issues to work through, first of which is that (Tuesday's meeting date) is a date field, not a date/time field.  The code for that formula field is below...does anyone have ideas on how to turn this into a formula that satisfies date/time criteria?  Secondly, I need to locate local midnight +1 minute for the Tuesday meeting.


Formula field to identify the next Tuesday's meeting date, based on the created date of the notes record.


IF(MOD( DATEVALUE( CreatedDate) - DATE(1900, 1, 7), 7)=0, DATEVALUE(CreatedDate) + 2,
IF(MOD( DATEVALUE( CreatedDate) - DATE(1900, 1, 7), 7)=1, DATEVALUE(CreatedDate) + 1,
IF(MOD( DATEVALUE( CreatedDate) - DATE(1900, 1, 7), 7)=2, DATEVALUE(CreatedDate) + 0,
IF(MOD( DATEVALUE( CreatedDate) - DATE(1900, 1, 7), 7)=3, DATEVALUE(CreatedDate) + 6,
IF(MOD( DATEVALUE( CreatedDate) - DATE(1900, 1, 7), 7)=4, DATEVALUE(CreatedDate) + 5,
IF(MOD( DATEVALUE( CreatedDate) - DATE(1900, 1, 7), 7)=5, DATEVALUE(CreatedDate) + 4,
IF(MOD( DATEVALUE( CreatedDate) - DATE(1900, 1, 7), 7)=6, DATEVALUE(CreatedDate) + 3,