Extend with TDTM¶
This solution utilizes the TDTM framework for all record-triggered automation, so that it can be controlled by the system admin alongside other NPSP automation.
Trigger Handler records can be modified to override/bypass a triggered event while troubleshooting, or to deactivate and replace the event with custom actions.
Extending TDTM¶
Salesforce documentation: https://help.salesforce.com/s/articleView?id=sfdo.NPSP_Deploy_Apex_TDTM.htm&type=5
Custom handlers should be in the global scope and extend TDTM_Runnable in the npsp namespace.
Example:
global with sharing class CustomSubledgerThings extends npsp.TDTM_Runnable {
global override npsp.TDTM_Runnable.DmlWrapper run(
List<SObject> newList,
List<SObject> oldList,
npsp.TDTM_Runnable.Action triggerAction,
Schema.DescribeSObjectResult objResult
) {
// TDTM has a feature to make efficient dml requests
// Add objects prepped for dml to TDTM_Runnable's DmlWrapper
npsp.TDTM_Runnable.DmlWrapper dmlWrapper = new npsp.TDTM_Runnable.DmlWrapper();
// Cast generic sobjects to sobject type
List<Opportunity> lstOpps = (List<Opportunity>) newList;
// Route trigger actions
if (triggerAction == npsp.TDTM_Runnable.Action.AfterUpdate) {
// Do accounting things
List<ssfs__Journal_Entry__c> entriesToUpdate = new List<ssfs__Journal_Entry__c>();
for (Opportunity opp : lstOpps) {
entriesToUpdate.add(
new ssfs__Journal_Entry__c(
ssfs__Credit__c = 100,
ssfs__GL_Code__c = '1-23-456'
)
);
}
dmlWrapper.objectsToUpdate.addAll(
(List<ssfs__Journal_Entry__c>) entriesToUpdate
);
}
// Return wrapper with added items to update
return dmlWrapper;
}
}