0

Hi i am new to salesforce, I want to create a validation rule on an Account object where Picklist field named as Ownership, I want

  • that when an user enter no value means null value there should be error
  • if user picks a value from picklist then it should save it means no error
  • and again if user tries to change the selected picklist, he should be able to do so
  • and later I want to bypass this validation rule to System Administrator Profile.

Here is this i have tried.

ISPICKVAL(PRIORVALUE( Ownership ),"Public")  || 
ISPICKVAL(PRIORVALUE( Ownership ),"Private") ||
ISPICKVAL(PRIORVALUE( Ownership ),"Subsidiary") ||  
ISPICKVAL(PRIORVALUE( Ownership ),"Other") ||
ISBlANK(Text(Ownership))

Untill didn't used the Check condition for blank the validation rule was working fine but now on every condition it is giving error.

1
  • 1
    These two comments should have been an edit to your question rather than a comment. I've made the change for you this time, and you can visit help center to get more information about the various features that stackexchange sites have.
    – Derek F
    Commented Sep 14, 2021 at 16:48

1 Answer 1

1

A better name for validation rules would be invalidation rules because when the formula evaluates to true, it means the rule complains and prevents the invalid data from being saved.

So the key here is to think about what data is invalid. Based on your description so far, that's:

  • Picklist cannot be null/blank (it must have a value selected)
  • ...if the user's profile is not 'System Administrator' (i.e. allow sysadmins to ignore the rule)

If you wanted nobody to be able to set a null value for a field, you could configure the field to be "required" (no explicit validation rule required there). If you want to make sure that only the configured picklist values can be used, there's a configuration option for that as well (no need to use a validation rule to specify that either).

Once you have a description of what makes a field invalid, it usually translates to a validation rule pretty well. In this case

AND(
    ISBLANK(TEXT(Ownership)),
    $Profile.Name <> 'System Administrator'
)

Everything inside an AND needs to be true for the result to be true. So if Ownership has a value, the validation rule allows the record to save. If the User's profile is Sysadmin, the validation rule will also allow the record to save (even if the picklist is becoming blank).

You may want to consider creating and using a Custom Permission instead of making a carve-out based on user profiles (though exemptions based on profiles are more beginner-friendly I'd argue)

6
  • "...exemptions based on profiles are more beginner-friendly..." <soapbox> Or in our case, you have an old Salesforce instance where everything was built around Profiles, and an old-school administrator "owner" of our org who basically refuses to even use Permissions for entirely new functionality (essentially because "that's not the way I did it"). Then you don't have much choice in the matter. </soapbox>
    – Moonpie
    Commented Sep 14, 2021 at 17:25
  • Actually, I didn't want to go this way, I want this to be done by validation rule is it possible.
    – Zain Khan
    Commented Sep 14, 2021 at 17:26
  • 1
    @ZainKhan I'm not quite sure what you're trying to say here. My approach does use a validation rule.
    – Derek F
    Commented Sep 14, 2021 at 17:56
  • Actually, I don't want to configure the field as required I want this to be done by validation rule using a formula and the same follows for user if he selects a picklist value apart from Null then at first trial it should be selected, and later if the user tries to change or update the field, he or she shouldn't able to do so. and I want all this to be done by validation rule no configuration part. As I am a new learner I have been given this scenario and he said to this by validation rule only no configuration part. I think you may be able understand what i am trying to say
    – Zain Khan
    Commented Sep 15, 2021 at 6:21
  • @ZainKhan : Yes, I believe he understands. Please thoroughly read his answer. Derek does give you a Validation Rule answer. He just suggests that you do it another way that is a "best practice" way of doing it instead of a Validation Rule.
    – Moonpie
    Commented Sep 15, 2021 at 14:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .