Validation rule problem

validation-rule

I have this two validation rules

The first to express that if the profile is Profile DS or the profile has the permission set ObligatoryPermission , the field Date must be required .

and for the second it is to express that if the profile is Profile DS OR the profile has the permission set ObligatoryPermission AND the status field which is picklist is terminated , the field Details will be required .

The problem that this is not respected . Some help please

And I have a question , how can I with the validation rule make a field disabled ?

OR(($Profile.Name = "Profile DS"),($Permission.ObligatoryPermission ),
ISBLANK(Date__c )
)

AND(ISPICKVAL(Status__c , "end"), ISBLANK(Details__c ),
OR(($Profile.Name = "Profile DS"),($Permission.ObligatoryPermission )))

Best Answer

Validation rules do their job when the result of the formula is true.

With that in mind, the issue with your current validation rule is that you're OR()-ing everything together. From basic boolean algebra, if any condition in an OR() is true, the entire statement is true. If your Date__c is blank, then nothing else matters.

To determine what your validation rule should be, it helps to piece it together in plain language first. Remember that the result of your formula needs to be true for it to take effect. You're not telling Salesforce when the data is valid, you're telling them when data is invalid.

Your plain language description is close, but a simple change will help illustrate what you need to do. I'd lay out your requirement as follows:

  • If this user has the "Profile DS" profile
  • or if they have the "ObligatoryPermission" permission
  • and Date__c is blank
  • then the data is invalid

You have two things you want to OR(), and then you want to AND() it with the final condition.

From that, the formula basically is already written

AND(
    OR(
        $Profile.Name = 'Profile DS',
        $Permission.ObligitoryPermission
    ),
    ISBLANK(Date__c)
)

It's not clear what you mean by "make a field disabled", so I won't touch on that.

Related Topic