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]; } } }
-------------------------------------------------------------------------------------------------------------------------
Once the Opportunity goes to Closed Won or Closed Lost, use a workflow rule to change the record type to, say, 'Closed'. Then, use a different page layout for the 'Closed' recordtype wherein all the fields are read only on layout 'Closed'
----------------------------------------------------------------------------------------------------------------------------
lock the whole record for everyone except System Admins once the level is "Archived" or "Closed". Putting a prior value around your level field will thus not help you, since it is only checking if that specific field has changed.
I would suggest you implement something like this:
- Create a new checkbox "Record Locked".
- Create a workflow that sets the checkbox to true once the level is "Archived" or "Closed". Optionally, you'd want to also uncheck this when the level changes again to another value.
- Update your validation rule so it says:
AND($Profile.Name <> 'System Administrator', Record_Locked__c = true)
------------------------------------------------------------------------------------------
You can do that with a combination of two validation rules working on current fields
Vallidation Rule 1
Prevent making any changes when Level equals Archived or Closed unless User is a Sys Admin. Needed to exclude situation when changes are done to Level because otherwise it will not allow to enter Archived or Closed.
PRIORVALUE
seems to not work here so I used ISCHANGED
function to capture that.AND(
$Profile.Name <> 'System Administrator',
NOT(ISCHANGED(Level__c)),
OR(
ISPICKVAL(Level__c, 'Archived'),
ISPICKVAL(Level__c, 'Closed')
)
)
The thing is that this rules allows making changes if User at the same time changes
Level__c
. That's why we need second Validation rule.Vallidation Rule 2
Prevents User from changing Level__c once it is Archived or Closed, unless he is a Sys Admin
AND(
$Profile.Name <> 'System Administrator',
ISCHANGED(Level__c),
OR(
ISPICKVAL(PRIORVALUE(Level__c), 'Archived'),
ISPICKVAL(PRIORVALUE(Level__c), 'Closed')
)
)
No comments:
Post a Comment