Activity Forums Salesforce Discussions Can we remove custom validation rule through Salesforce apex code?

  • Can we remove custom validation rule through Salesforce apex code?

     Parul updated 2 years ago 4 Members · 4 Posts
  • shariq

    Member
    July 18, 2017 at 1:46 pm

    How to remove custom validation rule through apex code?

  • Radhakrishna

    Member
    July 19, 2017 at 4:57 am

    Hello Shariq,

    It is common practice to have a boolean flag (say ByPass_VR__c), which can be set via Apex Code to skip it. Unless there is such a provision in this validation rule, you cant temporarily disable it via Apex code.

    The only 'work around' is to set field values such that the error formula doesn't evaluate to true.

    Example:

    AND(
    NOT(ByPass_VR__C),

    ..............

     

  • Adarsh

    Member
    March 28, 2018 at 10:42 am

    Hi shariq,

    The other solution is kinda like the second one. Introduce a dummy checkbox field that is not visible to anyone. And let the Validation Rule bypass the record if that checkbox is true. Now, in your trigger, before you update oppsToUpdate, first update that dummyCheckbox to true. In this way, the validation rule will be bypassed. Also, make sure you make the checkbox false as soon as the trigger does its action. In order to do this, you can create a workflow that will do the field update of that dummy checkbox to false whenever the value is true.

    Please let me know if you would need any help on this.

  • Parul

    Member
    September 15, 2018 at 2:36 pm

    I think you cannot remove custom validation rule through apex code but  there is only one solution is make a checkbox type field and then bypass the validation by using apex code.

     

     

    Thanks

Viewing 1 - 4 of 4 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos