3

I have the following Validation rule Active:

Error Condition Formula: ISPICKVAL(First_Ranking__c , "")

When I try to submit the visualforce page I'm getting the validation error asking to select.

Error: First Ranking: First Ranking is Required

Than I have tried doing something required = false but still getting the validation error:

<apex:inputField value="{!employee__c.First_Ranking__c}" required="false" />

So what I want to do is to ignore the validation error on the Visualforce page

8
  • It's not related, with your validation rule you have to provide value. At visualforce page you could force user to input field. you should deactivate your validation, or assign default value on page using apex:inputhidden Commented May 16, 2016 at 17:55
  • So you want to disable a Validation Rule only within the context of a Visualforce Page? Do you want to allow blank values or not?
    – Adrian Larson
    Commented May 16, 2016 at 17:56
  • @IlyaLepesh: I'm thinking the same way as you suggested which is deactivate but wondering is there any other way than deactivating
    – Nick
    Commented May 16, 2016 at 17:58
  • @AdrianLarson: disable a validation rule only wihtin the context of vfp, no blank values
    – Nick
    Commented May 16, 2016 at 17:59
  • Add another field, change validation to AND(ISPICKVAL(First_Ranking__c , ""),ISBLANK(field2)); pass field2 from page Commented May 16, 2016 at 18:00

1 Answer 1

5

If you only want to disable the Validation Rule within the context of a Visualforce Page, your best bet is to create a checkbox along the lines of Is_Validation_Exempt__c, and set it to true in your controller. Then change your rule to:

AND(NOT(Is_Validation_Exempt__c), ISPICKVAL(First_Ranking__c , ""))

To the above, you should add a Workflow Rule that updates the checkbox to false every time it gets checked. Since it fires after the Validation Rule, it will only affect subsequent saves.

4
  • 3
    N.B. the VR rule will use is_validation_exempt__c from the value in the database (i.e. saved by Controller) and hence will persist, essentially disabling the VR for this record, forever.
    – cropredy
    Commented May 16, 2016 at 18:21
  • @cropredy Good point and an easy fix. Updated my answer. Thanks for the catch!
    – Adrian Larson
    Commented May 16, 2016 at 18:25
  • @cropredy btw thanks for teaching me what NB stands for!
    – Adrian Larson
    Commented May 16, 2016 at 19:00
  • a small trade for your inspiring me to use the composition/fluent pattern :-)
    – cropredy
    Commented May 16, 2016 at 19:10

You must log in to answer this question.

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