0

We currently have a validation rule setup stating that if a Quote is not new and has the status of approved then dont allow users to edit the fields. The problem is that I want every one to be able to edit a field called IID__c regardless of status. I am not sure at this point how with my current conditions. Below is my code.

AND( 
$User.ProfileId != '00eU0000000ZMaV', 
$User.ProfileId != '00e0B000000eNK5', 
$User.ProfileId != '00eU0000000mLpf', 
!ISNEW(), 
TEXT(SBQQ__Quote__r.SBQQ__Status__c) != 'Draft', 
TEXT(SBQQ__Quote__r.SBQQ__Status__c) != 'Rejected', 
!SBQQ__Quote__r.In_Apex_Context__c, 
OR( 
ISCHANGED(SBQQ__Discount__c), 
ISCHANGED(SBQQ__AdditionalDiscountAmount__c), 
) 
)
  • Problem with this is that once you would add an exception when IID__c is changed, everyone would be able to bypass this validation and modify any other field(s) (unless you would also restrict specific field(s) modification(s)), once they also modified IID__c – o-lexi Jun 21 '18 at 18:47
1

The trick is to make it to where only the 1 field is allowed to be changed:

NOT(ISCHANGED(IID__c))

Add that into your formula instead of your OR and it will fire the rule if any field other than IID__c is changed. This is more efficient than trying to block at all fields except for the 1 you want edited.

Also, you should probably not use hard-coded ids. While it's probably mostly ok with profile since those Ids are fairly constant, it's just a best practice to use the name.

Lastly, what you're saying and what your code is saying are different. You say you want to stop all changes if status is accepted but your code says if the status is not draft or rejected. In this case you may have only the 3 status so it's probably the same thing, but if you added a 4th your rule would stop working. You want to make sure to do status = accepted

Something like this should work for a single field:

AND( 
    $Profile.Name != 'System Administrator', 
    $Profile.Name != 'Profile 2', 
    $Profile.Name != 'Profile 3', 
    !ISNEW(),
    NOT(ISPICKVAL(SBQQ__Quote__r.SBQQ__Status__c, 'Accepted')), 
    !SBQQ__Quote__r.In_Apex_Context__c, 
    NOT(ISCHANGED(IID__c))
)

Multiple fields

This should work for allowing only the specified fields to be changed if you need more than 1 field in your logic.

AND( 
    $Profile.Name != 'System Administrator', 
    $Profile.Name != 'Profile 2', 
    $Profile.Name != 'Profile 3', 
    !ISNEW(),
    NOT(ISPICKVAL(SBQQ__Quote__r.SBQQ__Status__c, 'Accepted')), 
    !SBQQ__Quote__r.In_Apex_Context__c, 
    NOT(OR(
        ISCHANGED(IID__c),
        ISCHANGED(Number__c)
    ))
)
  • What if I needed another field that is allowed to be changed such as Number__c? – Brooke Jun 21 '18 at 15:09
  • just add it right under the other one using the same syntax. Updated my answer – gNerb Jun 21 '18 at 15:10
  • I thought so but that didnt work. I think it is because within the AND statement they would both have to change – Brooke Jun 21 '18 at 15:11
  • @Brooke Try the new update, if any one of those changes OR will return true and it'll be negated (allowed) but if none of them change OR will be false and negated (true) – gNerb Jun 21 '18 at 15:17
  • Nope didnt work still got the validation when changing the value in either one – Brooke Jun 21 '18 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.