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
scottyscotty 

Validation rule based on ISBLANK

I am trying to write a validation rule that would allow an administrator to change a value in a lookup filed if it is not blank, but allow any one to change it if it is.  What I have below works other than you can not modify any other field in the object if you are not an Administration

 

NOT(ISBLANK(Outside_Sales_Rep__c))&& $Profile.Name <> "System Administrator"

Best Answer chosen by Admin (Salesforce Developers) 
Jeff MayJeff May

no problem at all.  Formulas can be very confusing trying to translate "English" to formulas -- especially validation rules where you are actually trying to write the reverse formula so the Rule is TRUE when what you want is FALSE.

 

I find it helps to write it in English first, then in formula-ese.

 

So, if the rule is

 

No matter who you are, you can change fields other than the Outside_Sales_Rep__c

If you are not an Admin, and the Outside_Sales_Rep__c field was empty, you can change it.

And, if you are an Admin, you can always change the Outside_Sales_Rep__c field.

 

that means we want to make sure the Validation Rule is TRUE only when the current user is not an admin AND they are trying to change the Outside_Sales_Rep__c field AND the Outside_Sales_Rep__c field was not empty before they tried to change it.

 

In other words, if the edit does not involve the Outside_Sales_Rep__c field, we don't care who makes it.  If it does involve the Outside_Sales_Rep__c field, then if the Outside_Sales_Rep__c field was not empty, only Admins can change it.

 

With me so far?

 

"if the edit involves the field":    PRIORVALUE(Outside_Sales_Rep__c)  <> Outside_Sales_Rep__c

"if the field was not blank":  PRIORVALUE(Outside_Sales_Rep__c)  <> ''

"if the user is not an Admin": $Profile.Name <> "System Administrator" 

 

Then we can put it together so that all 3 have to be TRUE to "fail" the Validation Rule:

 

AND(PRIORVALUE(Outside_Sales_Rep__c)  <> Outside_Sales_Rep__c, PRIORVALUE(Outside_Sales_Rep__c)  <> '', $Profile.Name <> "System Administrator")

 

Closer?

All Answers

Jeff MayJeff May


You want to check to see if the Outside_Sales_Rep__c field is part of the change but allow any other fields to change no matter what:

 

AND(PRIORVALUE(Outside_Sales_Rep__c)  <> Outside_Sales_Rep__c, NOT(ISBLANK(Outside_Sales_Rep__c))&& $Profile.Name <> "System Administrator")

scottyscotty

Thanks for the reply, This is very close. My issue is that if the field is not blank, I don't want other profiles to be able to change it, if it is blank, I want it to be able to be modified by any other profile. Not sure my context makes sense, but that is what I am looking for.

Jeff MayJeff May

Then you just need to mix/match AND() and OR()s to get the conditions you want.  The key difference from what you had was only caring about that field if it changed.  Otherwise, people can change the other fields with no restrictions.

scottyscotty

I am more confused that when I started.  My original rule worked to make it so if it was populated, you had to be a n admin to change it, but it also did notallow you to change any otehr field.  Now with your suggested mods, you have to be an adminstrator to change it either way, but y can change everything else with no issue.  Believe me, I am not complaining, i appreciate hte help, but I am so confussed.

Jeff MayJeff May

no problem at all.  Formulas can be very confusing trying to translate "English" to formulas -- especially validation rules where you are actually trying to write the reverse formula so the Rule is TRUE when what you want is FALSE.

 

I find it helps to write it in English first, then in formula-ese.

 

So, if the rule is

 

No matter who you are, you can change fields other than the Outside_Sales_Rep__c

If you are not an Admin, and the Outside_Sales_Rep__c field was empty, you can change it.

And, if you are an Admin, you can always change the Outside_Sales_Rep__c field.

 

that means we want to make sure the Validation Rule is TRUE only when the current user is not an admin AND they are trying to change the Outside_Sales_Rep__c field AND the Outside_Sales_Rep__c field was not empty before they tried to change it.

 

In other words, if the edit does not involve the Outside_Sales_Rep__c field, we don't care who makes it.  If it does involve the Outside_Sales_Rep__c field, then if the Outside_Sales_Rep__c field was not empty, only Admins can change it.

 

With me so far?

 

"if the edit involves the field":    PRIORVALUE(Outside_Sales_Rep__c)  <> Outside_Sales_Rep__c

"if the field was not blank":  PRIORVALUE(Outside_Sales_Rep__c)  <> ''

"if the user is not an Admin": $Profile.Name <> "System Administrator" 

 

Then we can put it together so that all 3 have to be TRUE to "fail" the Validation Rule:

 

AND(PRIORVALUE(Outside_Sales_Rep__c)  <> Outside_Sales_Rep__c, PRIORVALUE(Outside_Sales_Rep__c)  <> '', $Profile.Name <> "System Administrator")

 

Closer?

This was selected as the best answer
scottyscotty

It works perfectly.  I will save this in my rules folder for reference.  Thank you for your patience.

scottyscotty

With the validation rule that works for most issues I have on the account record.  I would like to modify it to allow another profile and the admin only to edit the filed if it is blank.  Here is my existing validation rule.  is this possible?

 

AND(PRIORVALUE(DST_Outside_Sales_Rep_Lookup__c) <> DST_Outside_Sales_Rep_Lookup__c, PRIORVALUE(DST_Outside_Sales_Rep_Lookup__c) <> '' , $Profile.Name <> "System Administrator")

AmandaodAmandaod

Brilliant answer which saved me lots of time, thank you @JeffM