+ Start a Discussion

Account Object Security Based on Task

Does anyone know how I can make an account read only if the a related task is not completed? If it is completed then the user would be able to edit the account again.
One way to do it might be to write a Task trigger that changes the value of a field in the Account, and then write a Validation Rule on Account that prevents certain user profiles from making any changes if the field is a particular value.
The task triggger sounds like it would work but How can I make changes to the account secruity based on user profile? I didn't know this was available through the standard functios
You're not changing account security.  You're using a Validation Rule to prevent any changes to the record from being saved.  The rule checks the value of your custom status field, and if it says locked, then the user cannot save any changes.

ic I'd probably use the ISPICKVAL for the custom field. If it contains value 'x' it locks the record...


but which function is it in the validation rules section to lock the record? 



It is the validation rule itself, there is no sub-function.  If the condition is met, the validtion rule prevents a save.  Have you used validation rules?

I have created many validation rules but maybe i wasn;t being clear before.


Basically, we are implementing a duplicate record monitoring system. When a user creates a duplicate company record, a task will be created for them. I want to lock the account record when this happens so they are forced to address and complete the task.


I thought u were saying that there is a function in validtion rules that can override the record level security based on a fields'scondition.  So the idea is , create a task trigger that updates a custom field in the account.  Once the field is updated, it will lock the account based on this val rule that you suggested


When they complete the task, it will udpate the account field again which will then allow the user to edit the record again.


thanks again


When you lock the account record, you want to prevent the user from changing any field in the record, correct?


Create a custom Locked checkbox field in the Account object, then create this Validation Rule:


AND( Locked__c = True, NOT($Profile.Name = "System Administrator") )



and set the rule's error message is "record is locked".


When a standard user edits a locked account and tries to save his changes, the rule fires.  The rule can't prevent the user from clicking the Edit button, but it prevents the save.


If you want the user to be able to modify some fields but not others in the record, then this will not work.

Message Edited by dmcheng on 02-10-2010 05:39 PM
This is great. That should work- one question, is there a way we can lock the record for only the person that owns the record? Everyone else should still be able to edit
change the profile.name equation to compare owner name to the current user instead.



I got the rule to work but the problem is the locked__c will not update from the task trigger now since this rule is in the way. So everytime the task trigger tries to update it, I get this rule. Is there anyway to let the locked__c field to update to yes but it locks the record unless the user changes it to No.


AND( ISPICKVAL(Locked__c, "Yes"), ( $User.Id = OwnerId ) )

Message Edited by bikla78 on 02-11-2010 12:33 PM
Message Edited by bikla78 on 02-11-2010 12:34 PM
are you running the task trigger as before or after?  Try before.

Right now, I am just manually testing this validation rule. So I am manually trying to change the locked picklist. However, it won't let me change the value to Yes because this validation rule is in the way. I think an After update trigger will work initially so when the task is created the trigger will fire and update the locked  field to yes. Then, when a user tries to edit the record, they will get the validaiton message:


"The record is locked, please complete the task associated with this company"


However, once the user complete the task the trigger, it should update the task field fro Yes to  No now but the problem is, how would it update it back if it is locked?



Message Edited by bikla78 on 02-12-2010 11:37 AM
Triggers run in the system context so it should be able to change the lock  field.