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
miteshsuramiteshsura 

deactivate validation rule in APEX

Hi,

 

Is there a way to deactive a validation rule in APEX. I want to update a record from APEX, but do not want to fire Validation rule, if the same rule is fired from UI, validation rule should fire. 

 

I am thinking to deactive just before record.update and active again. Can this be done? Is there any other way to acheive this? 

 

thanks for the time.

Mitesh

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

The way we've handled this in the past is to set a field on the record to indicate it was updated programmatically and adjust the validation rule to exclude those records that have that field set.

All Answers

bob_buzzardbob_buzzard

The way we've handled this in the past is to set a field on the record to indicate it was updated programmatically and adjust the validation rule to exclude those records that have that field set.

This was selected as the best answer
miteshsuramiteshsura

why I did not think of that before?? probably I come from tradtional development background.. thanks for the idea.. 

anilmcaanilmca
Hey bob, This approach is not working for me, because i have validation rule which is dependent on newly Added field, whenever we set a value to that field, validation also get fired. please suggest if any solution for that. Thanks in Advance.
bob_buzzardbob_buzzard

Can you explain what you mean by newly added field? 

Bala.DamaBala.Dama
Please go through below url. you will get some idea how to do. Its worked for me.
http://bobbuzzard.blogspot.in/2011/11/bypass-validation-rules-from-apex.html
Ezra Kenigsberg @ BCEzra Kenigsberg @ BC
Here's a better way to bypass Validation Rules (https://sites.google.com/site/ezrakenigsberg/blog/abetterwaytobypassdatavalidation)--involves fewer steps.