Skip to main content
Paddy R 님이 #Customer Service에 질문했습니다
I am running one batch job and during that execution , I need to disable one validation rule on Account. Is that possible?

 

Thank you.
답변 9개
  1. 2013년 8월 28일 오후 5:24
    Hey Pradeep,

     

    I have a Solution for you:

     

    1. Go to Setup | Develop | Custom Settings.

     

    2. Click New and name it say VR Batch Exclusion Setting.

     

    3. Set the Setting Type as: Hierarchy.

     

    4. Visibility: Public.

     

    5. Click Save.

     

    Now, under the 'Custom Fields' section, click New and add a Checkbox: Is Batch Excluded.

     

    1. Once that is done, click on 'Manage'.

     

    2. Just above the 'Default Organization Level Value', click New.

     

    3. Un-check the Checkbox.

     

    4. Save.

     

    Now, you can go to the VR and the use the Insert Field button to get this checkbox value like as below:

     

    $Setup.VR_Batch_Exclusion_Setting__c.Is_Batch_Excluded__c and the you could reframe the VR as:

     

    AND(

     

    NOT($Setup.VR_Batch_Exclusion_Setting__c.Is_Batch_Excluded__c),

     

     ......

     

    )

     

    Now the best part is, we can modify this value of the checkbox via Code just like this:

     

    VR_Batch_Exclusion_Setting__c t =

     

     [

     

        SELECT

     

                    Id,

     

                    Is_Batch_Excluded__c

     

        FROM

     

                    VR_Batch_Exclusion_Setting__c

     

        LIMIT 1

     

    ];

     

    t.Is_Batch_Excluded__c = TRUE;

     

    UPDATE t;

     

    So, in short just before you Insert the record UPDATE the value to TRUE so the VR will not run and once when the INSERT is done, you can UPDATE the checkbox back to FALSE.

     

    Best,

     

    Deepak