• #21083
    Salesforce | shariq shariq #959
    Forcetalks

    Can we remove custom validation rule through Salesforce apex code?

    How to remove custom validation rule through apex code?

     

    #21092
    Salesforce | Radhakrishna Radhakrishna #943
    Forcetalks

    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),

    …………..

     

    #26801
    Salesforce | Adarsh Adarsh #958
    Forcetalks

    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.

    #34372
    Salesforce | Parul Parul #953
    Forcetalks

    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 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.

Popular Salesforce Blogs

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2020 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?