AnsweredAssumed Answered

Field validation question

Question asked by dsimonson on Dec 15, 2017
Latest reply on Dec 16, 2017 by dsimonson

I have a solution that allows certain users to be designated as "Admin" via a checkbox (tied to a number field, "is_admin".  The first user to open the app is designated Admin and has the check, but designating additional users (who can only be added by an Admin) is optional. 


Here's my problem/question:  These Admin users may "turn off" their admin privilege by unchecking the box - which is fine as long as _one_ Admin user is left, otherwise no one would be able to administer the app.  What is the best way to make sure that there is at least _one_ admin user left - such that when the last admin user tries to uncheck her box, she is told she can't because she is the last one?


I am thinking about trying it via a validation calculation on the is_admin field.  Here's my first attempt:


If ( Count ( is_admin ) > 1; 1 ; 0 )


my understanding is that validation fails if the results of the validation calculation are false/0 - so if the last admin user unchecks their box, the field will give my validation message of "I'm sorry - you are the last Admin user.  You cannot uncheck your Admin status or no one will be able to administer this app"


Will this work, or do I need to make it a script trigger and do it at the "on object validate" trigger?