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
Justin PRJustin PR 

Validation Rule Question

I am trying to make a validation rule that will accomplish the following, but can't get my head around the logic.

 

If a certain checkbox field is checked, don't allow anyone except an admin to edit the record.  The only exception to this is that a specific profile can edit a specific picklist field to 3 specific values, but nothing else.

 

 

I can do the first half no problem, but the second half is giving me a hard time.  Any help is appreciated. 

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

I think that if you rephrase your criteria in terms of how validations rules work, it becomes clearer.

 

Validation Rules are not about when you *can* do something it's when you can't.

 

So, couldn't you create two validation rules instead of just one.

 

Rule 1.   if the profile is the manager and the picklist value is not one of the three legal ones - error.

 

and (

($Profile.Id = "manager id"),

(not(ispickval(status__c,"legal 1"))) ,

(not(ispickval(status__c,"legal 2"))) ,

(not(ispickval(status__c,"legal 3"))) 

)

 

 

Rule 2.  if the profile is not manager and not admin and the checkbox is checked - error.

 

and (

not(($Profile.Id = "manager id")),

not(($Profile.Id = "admin id")),

(Invoiced__c = true)

)

 

 

Now, you can certainly merge these into one rule by throwing parens around both of them and OR'ing them, but perhaps distinct error messages would be better?

 

I hope I've understood your needs and this helps.  Best, Steve.

All Answers

NasipuriNasipuri

Hi ,

You can use ISPickval function (ISPICKVAL(picklist_field, text_literal)
Checks whether the value of a picklist field is equal to a string literal
) to write the validation rule .

 

This will solve your problem.

 

Thanks,

Dinesh Nasipuri

Dinesh.Nasipuri@gmail.com

 

Justin PRJustin PR

This is what I have so far:

 

 

OR(AND (Invoiced__c, NOT ($Profile.Id = "xxxxxx")),
AND (NOT ($Profile.Id = "yyyyyy"), NOT(ISPICKVAL( Status__c, "Sent")), NOT(ISPICKVAL( Status__c, "Hired")), NOT(ISPICKVAL( Status__c, "Lost"))))

 

 

 

Profile XXXXXX is able to change the picklist, but not anything else (this was the admin profile that is supposed to be able to change everything).

 

Profile YYYYYY isn't able to change anything.

 

Any ideas how I can correct the forumla above to meet the criteria in my earlier post?

Message Edited by Justin PR on 11-16-2009 12:32 PM
Message Edited by Justin PR on 11-16-2009 12:33 PM
NasipuriNasipuri

Hi ,

 

You can try something like this :

 

AND (
validated__c =TRUE ,
$Profile.Name = "YYYYY",
AND(
NOT(ISPICKVAL( Status__c, "Sent")),
NOT(ISPICKVAL( Status__c, "Lost"))
)
)

 

Where YYYYY is the Non admin Profile Name .

Justin PRJustin PR
That wouldn't test for the admin profile though right?
deepzdeepz

Expanding on the above suggested and also on a solution I had suggested for another of your query

 

OR(
  AND(
        ISCHANGED(Invoiced__c) ,
        NOT(Invoiced__c),
        NOT($Profile.Id = "xxxxxx")),
  AND(
        NOT(ISPICKVAL( Status__c, "Sent"),
        NOT(ISPICKVAL( Status__c, "Lost"),
        NOT(ISPICKVAL( Status__c, "Hired"))
  )

 

Hope I got your requirement right.

Justin PRJustin PR

Thank you for the suggestion, but that doesn't take the other profile into account.

 

 

Admin profile - needs to be able to edit anything regardless of any criteria

 

manager profile -  can edit a specific picklist field to 3 specific values, but nothing else.

 

other profiles - can't edit anything if the checkbox is checked, otherwise can edit everything

SteveBowerSteveBower

I think that if you rephrase your criteria in terms of how validations rules work, it becomes clearer.

 

Validation Rules are not about when you *can* do something it's when you can't.

 

So, couldn't you create two validation rules instead of just one.

 

Rule 1.   if the profile is the manager and the picklist value is not one of the three legal ones - error.

 

and (

($Profile.Id = "manager id"),

(not(ispickval(status__c,"legal 1"))) ,

(not(ispickval(status__c,"legal 2"))) ,

(not(ispickval(status__c,"legal 3"))) 

)

 

 

Rule 2.  if the profile is not manager and not admin and the checkbox is checked - error.

 

and (

not(($Profile.Id = "manager id")),

not(($Profile.Id = "admin id")),

(Invoiced__c = true)

)

 

 

Now, you can certainly merge these into one rule by throwing parens around both of them and OR'ing them, but perhaps distinct error messages would be better?

 

I hope I've understood your needs and this helps.  Best, Steve.

This was selected as the best answer
Justin PRJustin PR

Steve,

 

This was really helpful and is getting me a lot closer.  Will rule #1 prevent the manager for editing anything other than the picklist value?  If that field is checked, all they can update is that specific picklist to those specific values.

 

Thanks for your help on this - I think we've almost solved it!

SteveBowerSteveBower

Hi, sorry, I just saw your followup question:

 

No, that validation rule doesn't say anything about any other fields, etc.   *All* it says is, if you're a manager, and you set that particular field to something other than those three values, it's an error.  If you're a manager you can set anything else you want and this validation rule won't complain.

 

If you need to restrict the manager from editing anything other than that field to one of three values, then you either need more validations or to write a before update Apex trigger.

 

You could write a long validation rule with a term for each field like (in pseudo code):

 

and(

   profile=manager,

   or(

       ischanged(field1),ischanged(field2),ischanged(field3)......

       )

     )

Justin PRJustin PR
That solved it - thank you!