From a760d9746c16041039bf941c5d3a6ab869741966 Mon Sep 17 00:00:00 2001 From: Reede Stockton Date: Thu, 3 Mar 2022 12:45:44 -0800 Subject: [PATCH 1/2] Preliminary working npsp fix --- dlrs/main/classes/RollupController.cls | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dlrs/main/classes/RollupController.cls b/dlrs/main/classes/RollupController.cls index e4d38c50..61821c8e 100644 --- a/dlrs/main/classes/RollupController.cls +++ b/dlrs/main/classes/RollupController.cls @@ -215,6 +215,8 @@ public with sharing class RollupController { : (' // Force the ' + RollupTriggerName + ' to be invoked, fails the test if org config or other Apex code prevents this.\n' + + ' Callable npspApi = (System.Callable)Type.forName(\'npsp\', \'Callable_API\').newInstance();\n' + + ' Boolean isNpspTriggerDisabled = (Boolean)npspApi.call(\'TDTM.DisableAllTriggers\', new Map());\n' + ' ' + (namespace.length() > 0 ? namespace + '.' : '') + 'RollupService.testHandler(new ' + From 49ecf0666687057d98cb6f752d83a33cc99146c6 Mon Sep 17 00:00:00 2001 From: Reede Stockton Date: Sun, 20 Mar 2022 16:28:28 -0700 Subject: [PATCH 2/2] Turn off npsp tdtm when deploying test code. --- dlrs/main/classes/RollupController.cls | 3 +-- dlrs/main/classes/RollupControllerTest.cls | 1 + dlrs/main/classes/RollupService.cls | 21 +++++++++++++++++++++ dlrs/main/classes/RollupServiceTest.cls | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/dlrs/main/classes/RollupController.cls b/dlrs/main/classes/RollupController.cls index 61821c8e..95a08338 100644 --- a/dlrs/main/classes/RollupController.cls +++ b/dlrs/main/classes/RollupController.cls @@ -215,8 +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' + - ' Callable npspApi = (System.Callable)Type.forName(\'npsp\', \'Callable_API\').newInstance();\n' + - ' Boolean isNpspTriggerDisabled = (Boolean)npspApi.call(\'TDTM.DisableAllTriggers\', new Map());\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;