diff --git a/dlrs/main/classes/RollupController.cls b/dlrs/main/classes/RollupController.cls index e4d38c50..95a08338 100644 --- a/dlrs/main/classes/RollupController.cls +++ b/dlrs/main/classes/RollupController.cls @@ -215,6 +215,7 @@ public with sharing class RollupController { : (' // Force the ' + RollupTriggerName + ' to be invoked, fails the test if org config or other Apex code prevents this.\n' + + ' RollupService.disableNpspTdtm();\n' + ' ' + (namespace.length() > 0 ? namespace + '.' : '') + 'RollupService.testHandler(new ' + diff --git a/dlrs/main/classes/RollupControllerTest.cls b/dlrs/main/classes/RollupControllerTest.cls index 335c7a48..2102edeb 100644 --- a/dlrs/main/classes/RollupControllerTest.cls +++ b/dlrs/main/classes/RollupControllerTest.cls @@ -227,6 +227,7 @@ private class RollupControllerTest { ' // Force the ' + controller.RollupTriggerName + ' to be invoked, fails the test if org config or other Apex code prevents this.\n' + + ' RollupService.disableNpspTdtm();\n' + ' ' + Utilities.classPrefix() + 'RollupService.testHandler(new ' + diff --git a/dlrs/main/classes/RollupService.cls b/dlrs/main/classes/RollupService.cls index 59d6c32d..0450b2ae 100644 --- a/dlrs/main/classes/RollupService.cls +++ b/dlrs/main/classes/RollupService.cls @@ -1559,6 +1559,27 @@ global with sharing class RollupService { lookupWrapper.AggregateAllRows); } + /** + * Check if npsp is installed and TDTM can be disabled with Callable_API + **/ + private static Boolean npspInstalled() { + if (Type.forName('npsp', 'Callable_API') != null) { + return true; + } + return false; + } + + /** + * If possible, disable npsp tdtm triggers with Callable_API + **/ + public static void disableNpspTdtm() { + if (!npspInstalled()) { + return; + } + Callable npspApi = (System.Callable) Type.forName('npsp', 'Callable_API').newInstance(); + npspApi.call('TDTM.DisableAllTriggers', new Map()); + } + /** * Wrapper around DML allowing with or without sharing to be applied and all or nothing exception handling **/ diff --git a/dlrs/main/classes/RollupServiceTest.cls b/dlrs/main/classes/RollupServiceTest.cls index 23bb6ae6..c38ce456 100644 --- a/dlrs/main/classes/RollupServiceTest.cls +++ b/dlrs/main/classes/RollupServiceTest.cls @@ -963,6 +963,9 @@ private with sharing class RollupServiceTest { if (!TestContext.isSupported()) return; + // If NPSP is present, disable NPSP TDTM triggers. They distort the limit counts. + RollupService.disableNpspTdtm(); + // Disable the Account trigger for this test, its carefully caluculated test actuals are thrown when this is enabled as well TestContext.AccountTestTriggerEnabled = false; @@ -1082,6 +1085,9 @@ private with sharing class RollupServiceTest { if (!TestContext.isSupported()) return; + // If NPSP is present, disable NPSP TDTM triggers. They distort the limit counts. + RollupService.disableNpspTdtm(); + // Disable the Account trigger for this test, its carefully caluculated test actuals are thrown when this is enabled as well TestContext.AccountTestTriggerEnabled = false;