NPSP
NPSP copied to clipboard
#1795 - OldList searialized.
Critical Changes
Changes
In this fix I am serializing oldList for classes that are called in future context using TDTM framework. Also, I am not serializing newList to prevent unintentional overwriting of fields on the passed sObject. Followed by writing new test cases to check the new functionality.
Updated following files: src\classes\TDTM_Runnable.cls src\classes\TDTM_Runnable_TEST.cls src\classes\TDTM_TriggerHandler.cls
Added following files: src\classes\ERR_SerializeOldListForAsync_TEST.cls src\classes\ERR_SerializeOldListForAsync_TEST.cls-meta.xml
Issues Closed
#1795
New Metadata
ERR_SerializeOldListForAsync_TEST.cls
Deleted Metadata
**lurch: attach W-008581
Tracking W-008581
Also resolves Issue #4662
@coriobriensfdo just curious on what is the status for this pull request?
@manikrai29 I don't have an update unfortunately, other than it's been checked by our developer/Product Manager teams and is sitting in the backlog. Once a scrum team has a chance to dive deeper into the code and merge it you'll see updates here.
@manikrai29 I'm looking back through your PR and have a question about usage. Currently, the TDTM_Runnable.runFuture()
method is not exposed as usable in customer orgs. Given that we currently do not support asynchronous TDTM handlers for customer-built TDTM, I was wondering if you submitted this PR so that we could support asynchronous handlers (with serialized content) for your use or if there was something else driving this? Basically, if we made this change as submitted you (or any customer) would not be able to use it. What I'm trying to determine is if there is a need to expand async tdtm as a global method (noting that NPSP does not use asynchronous triggers currently)?
@force2b As far as my understanding goes we don't need TDTM_Runnable.runFuture() method to run them as future methods. All we need to do is 'Asynchronous__c = true' for that particular trigger handler record and then that class is called in future context. So, I opened up this pull request to fix the issue where I needed serialized records in a class running in future context using TDTM.
To back up my findings below is the peice of code that leads to the behaviour I just mentioned above. I got this code from TDTM_TriggerHandler.cls -> runClass() method.
`if (classInstance instanceof TDTM_Runnable) { TDTM_Runnable classToRun = (TDTM_Runnable)classInstance; Boolean async = Boolean.valueOf(classToRunRecord.get('Asynchronous__c')); Boolean isBefore = (thisAction == TDTM_Runnable.Action.BeforeInsert || thisAction == TDTM_Runnable.Action.BeforeUpdate || thisAction == TDTM_Runnable.Action.BeforeDelete);
//A class can only run asynchronously (calling a future) if we have the ids of the
//records we want to affect. This means we can only run it for after in insert.
//Also,a future cannot be called from a future or batch method.
**if (async && !isBefore && !System.isFuture() && !System.isBatch()) {
UTIL_Debug.debug(LoggingLevel.WARN, '****Calling asynchronously: ' + classToRunName + ' for ' +
describeObj.getName() + ': ' + thisAction + ' with ' + (newList != null ? newList : oldList).size() + ' records');
runAsync(classToRun, classToRunName, newList, oldList, thisAction, describeObj);**
} else {
UTIL_Debug.debug(LoggingLevel.WARN, '****Calling synchronously: ' + classToRunName + ' for ' +
describeObj.getName() + ': ' + thisAction + ' with ' + (newList != null ? newList : oldList).size() + ' records');
return classToRun.run(newList, oldList, thisAction, describeObj);
}
}`
Thanks @manikrai29. You're absolutely correct. I mis-read the method functionality. The runAsync
method will call the runFutureNonStatic
method which will in turn call the run
method of the trigger handler.
@force2b can you tell me what is the status of this PR? Its been more than 4 months and no feedback 😄.
@manikrai29 Actually that's why I started asking some questions about this. We're looking to get this into an upcoming sprint. Now that I'm clearer on the objectives and changes, I can properly build out the acceptance criteria in our work item backlog.