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
odie123odie123 

Bypassing validation rules

Hi,

 

I have a bunch of validation rules on the account object> have avisual force page that saves some changes into the  account Object. In sthis special case I do not want the validation rules to fire.

 

I tried implementing this by

1) checking a custom check box from the Apex code before making the special update from the controller.

2) unchecking the check box after i have made my special update;

 

I look for this flag in my validation rule to skip that rule if it is checked.

 

But ths does not seeme to work as it seems like there are some commit issues. I am unable to by pass the validation rule. Any ideas on how to solve this?

 

thanks,

Odie

 

 

 

 

sfdcfoxsfdcfox
Usually, I write validation triggers instead, because then I can check to see if they should be processed via a global static boolean value. You can't reliably avoid validation rules in Apex Code (but there's a feature request on the IdeaExchange). On the other hand, you can use a @future method or a workflow field update in your code to turn off the flag after you're done (if the flag is already set, unset it and return early instead of doing the normal processing).
ArtabusArtabus

In VisualForce, check the "immediate" attribute to bypass validation rules. Taken from the doc :

<attribute immediate>

A Boolean value that specifies whether the action associated with
this component should happen immediately, without processing
any validation rules associated with the fields on the page. If set to
true, the action happens immediately and validation rules are
skipped. If not specified, this value defaults to false.

<>

sfdcfoxsfdcfox

I've seen that a dozen times and never fully grasped that. See, we all learn something new every day.

Vishal (Sops)Vishal (Sops)

if my trigger updates this value not a vf page, then how am I supposed to skip validation rules. Is there any immediate attribute in apex code?

Jerun JoseJerun Jose
be wary of using the immediate attribute. It skips the validation by not calling the setter methods when the control goes to the controller. So if you are looking for some elements from view state on your controller method, you wont have them