I need a way to lock an Idea and its comments from being editable. I have a time-based workflow already set up to change a custom field after 30 days. The custom field is called voting status with options of "Open" and "Locked". I'm thinking of two options:
Create a trigger to lock the record down after the field change similar to how it locks after an approval process is locked.
Or create a trigger that makes the record read-only after the field change.
Any ideas or examples on how to achieve this? I've been searching the API documentation and found the FOR UPDATE statement, but I haven't been able to implement anything.
Example so far:
Trigger IdeaRecordLock on Idea (after update, after insert) { for (Idea a : Trigger.New) { if (a.Voting_Status__c == 'Locked') { List lockemSockem = [SELECT Id FROM Idea WHERE Voting_Status__c = 'Locked' FOR UPDATE]; } } }
FOR UPDATE
is intended to be used to lock records only during the context of the running process of a trigger or class. This prevents other users, triggers or classes from modifying those records during the running context/instance of that trigger or class. Its not intended for use as means of permanently locking the records that are returned.