You need to sign in to do that
Don't have an account?
Teach_me_how
How to implement Test.isRunningTest() in Validation Rule?
I dont want to execute validation rule upon running test class?
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
I dont want to execute validation rule upon running test class?
I have followed the following method for test methods, data loading etc.
1. Create a boolean field in User object - IsValidationRuleAllowed?
2. Set the field value appropriately whether you want the validation rule to be executed for the corresponding user
3. Use this field in all the validation rules
4. When creating users in test method, set this field appropriately.
5. Validation rules will not run for the corresponding test method user.
Thanks
Bhuvana
You can do this using custom settings, here is the process:
1) Create a custom setting (for e.g "TurnOffValidationRule" and a boolean "TurnOff" field in it)
2) Now you can access the custom setting in validation rule like this:
$Setup.TurnOffValidationRule__c.TurnOff__c , put this in IF condition before anything
3) From test class you can make this "TurnOff__c" to true
Now when you execute your test class your validations will not be executed.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
I like the idea of custom setting but i dont like to modify existing test class to consider the custom setting. too many existing test class
AM sorry there is no other straight forward option.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
First add a custom Hierachy setting of "Testing". Add a field called "SeeAllData". Set the default value to "false". Add an organizational default to set the default to true.
You can now test if your custom setting are visible in your validation rule... Here is an example. Lets say you have a validation rule that only applies when a particular custom setting is set:
$Setup.AdminByPass__c.IsIT__c
If you did not want this validation rule to block testing, you would extend this with:
OR($Setup.AdminByPass__c.IsIT__c,NOT($Setup.Testing__c.SeeAllData__c))
The way this works is simply when running without SeeAllData, even the organizational default is not visible. So the value of "false" is seen. But if you are not running a test class, or you are running a test class where SeeAllData is set to true, then the organizational default is seen.
No modifications to your test classes are needed...