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
Amitkumar15Amitkumar15 

Valiadtion rule is not working

I have valiadtion rule which should allow 2 profiles to allow changes to only 3 fields.

 

below is rule but this is not working when i am changing others fields along with fields which is mentione din validation rule:

 

AND(NOT(OR(
ISCHANGED(Close_Date__c),
ISCHANGED(Status__c),
ISCHANGED(Delivery_Date__c)
)),
OR(
($Profile.Name="Profile1"),
($Profile.Name="Profile2")
))

 

 

Any help on this...Its Urgent...

Best Answer chosen by Admin (Salesforce Developers) 
Marko LamotMarko Lamot

In that case you have to reformulate your formula to check if fields that should NOT be changed are changing. 

 

AND(

OR

(

ISCHANGED(field_that_shouldn_be_changed_1),
ISCHANGED(field_that_shouldn_be_changed_2),

.....
)

,

 

OR

(
$Profile.Name="Profile1",
$Profile.Name="Profile2"
)

)

 

By the way: why don't you put this requirement into profile field level security?

 

All Answers

Marko LamotMarko Lamot

AND(

OR(
ISCHANGED(Close_Date__c),
ISCHANGED(Status__c),
ISCHANGED(Delivery_Date__c)
),
$Profile.Name<>"Profile1",

$Profile.Name<>"Profile2"
)

 

ryanjuptonryanjupton

MarkoLamot. Am I reading that right? We want to throw a validation erro if any of those three fields changed AND the user is not Profiel1 AND not Profile2?

Marko LamotMarko Lamot

Yes, that's amitkuram wants "should allow 2 profiles to allow changes to only 3 fields.".

Is he? 

Marko LamotMarko Lamot

Or he maybe want that those two profiles are allowed to change only these three fields. Well, than my formula is not OK. But in that case, why put this in validation rule. It's more appropiate to lock other fields via field level security.

ryanjuptonryanjupton

I would have thought it needed an OR between the profiles since no one will ever be Profile1 AND Profile2. What am I missing?

Marko LamotMarko Lamot

it will throw an error if user with profile3 will change any of those three fields (what I thought it was the requrement; but I'm not sure anymore):

 

profile3 is not equal to profile1 (TRUE) AND profile3 is not equal to profile2 (TRUE) AND if fields change (TRUE)   -> TRUE -> Error

 

Amitkumar15Amitkumar15

Thank you Ryan and Morkol for your response.

 

My requirement  is to allow profile1 and profile2 to update only 3 fields(Close_Date__c,Status__c,Delivery_Date__c).

 

and this validation rule is not working..

Marko LamotMarko Lamot

In that case you have to reformulate your formula to check if fields that should NOT be changed are changing. 

 

AND(

OR

(

ISCHANGED(field_that_shouldn_be_changed_1),
ISCHANGED(field_that_shouldn_be_changed_2),

.....
)

,

 

OR

(
$Profile.Name="Profile1",
$Profile.Name="Profile2"
)

)

 

By the way: why don't you put this requirement into profile field level security?

 

This was selected as the best answer
Amitkumar15Amitkumar15

Those 2 profiles can enter values in those 3 fields while creating record but they can't update it later.

 

can this be achieve from FLS?

ryanjuptonryanjupton

FLS doesn't allow this level of granularity. Can you please mark