-1

I wanted to know What are the ways by which we can bypass validation rule?

7
  • 2
    You can't "bypass" validation rules. They're validation rules. You can, however, design rules that can't be broken in the UI but can in code.
    – sfdcfox
    Jul 4, 2018 at 2:57
  • 1
    Possible duplicate of Add a Profile Exception to Validation Rule
    – David Reed
    Jul 4, 2018 at 3:17
  • by entering a value that passes the validation?
    – Eric
    Jul 4, 2018 at 3:23
  • I find it easy to get them to pass validation for special cases.. like for example they want to validate for all users but a "Super user" by giving a custom permission assigned to a permission set and give it to a user.. Access it in validation rule using $Permission.permissionNameHere to determine if i need to process it. however - validation rules by design are meant to run always
    – Ronnie
    Jul 4, 2018 at 3:49
  • I know they are validation rules, we cant bypass them but I came to know through code we can. I wanted to how through code we can bypass. Kindly help
    – Prapti
    Jul 4, 2018 at 4:01

2 Answers 2

1

I suppose first question here you needs to clarify is what do you mean by bypassing the validation rules?

If you mean to write validation rule in such a way that for some users or some profiles it just don't apply then there are some links already shared in the comments,

If you are looking for a way so that you can insert, update records even if any record fail due to validation rule then you can use following methods of Database class.

Datebase.insert(recordToInsert, allOrNone)

The optional allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why.

Database class

Remember here you are not bypassing the validation rules, with help of these methods you are only making sure that other records get saved in database.

3
  • This is a good answer, just not to the question posed by the OP
    – Eric
    Jul 4, 2018 at 5:51
  • @Eric My thought is OP failed to frame their question properly, So i guessed this information could help OP in some manner. Other wise this question is already flagged to close.
    – Mr.Frodo
    Jul 4, 2018 at 5:58
  • @Eric I think now this answer looks more relevant.
    – Mr.Frodo
    Jul 4, 2018 at 6:11
0

There are a couple of possible solutions to this but the simplest one is to add a field "bypass validation rules" on the user object.

Then, for all applicable rules you can add this in front:

(! $User.bypass_validation_rules__c ) && ... 

So, if you want to bypass the rules (for example to ease a big data load), you just need to flip this switch on the user.

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