Skip to content

Commit

Permalink
Merge pull request #1171 from SFDO-Community/feature/integrate-npsp-tdtm
Browse files Browse the repository at this point in the history
Feature/integrate npsp tdtm
  • Loading branch information
Szandor72 authored Mar 28, 2022
2 parents 72aee46 + 2fa53e7 commit 8afe2a8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions dlrs/main/classes/RollupController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
1 change: 1 addition & 0 deletions dlrs/main/classes/RollupControllerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
21 changes: 21 additions & 0 deletions dlrs/main/classes/RollupService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object>());
}

/**
* Wrapper around DML allowing with or without sharing to be applied and all or nothing exception handling
**/
Expand Down
6 changes: 6 additions & 0 deletions dlrs/main/classes/RollupServiceTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 8afe2a8

Please sign in to comment.