Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger handlers for multiple objects in same transaction treated as Consecutive #35

Closed
mikbranchaud opened this issue Jul 26, 2021 · 4 comments · Fixed by #37
Closed
Labels
bug Something isn't working
Projects

Comments

@mikbranchaud
Copy link

mikbranchaud commented Jul 26, 2021

Describe the bug
I have Trigger Handlers on two different objects, A and B. Handler A has DML on object B. When processing handler for Object A, rflib_TriggerManager.ACTIVE_HANDLER is set. When the DML on object B is executed, the rflib_TriggerManager
.runHandlers script skips the handler.run line since ACTIVE_HANDLER is not null and goes to handler.onConsecutiveRun.

Version
2.1. No

Code Snippets
private static rflib_TriggerHandler ACTIVE_HANDLER;
private static void runHandlers(rflib_TriggerManager.Args args, List handlers) {
for (TriggerHandlerInfo handlerInfo : handlers) {
rflib_TriggerHandler handler = handlerInfo.handler;

        LOGGER.debug('Is consecutive run? ' + (ACTIVE_HANDLER != null));

        if (ACTIVE_HANDLER == null) {
            try {
                ACTIVE_HANDLER = handler;
                handler.run(args);
            } catch (Exception ex) {
               //stuff
            } finally {
                ACTIVE_HANDLER = null;
            }
        }

        if (ACTIVE_HANDLER != null) {
            try {
                handler.onConsecutiveRun(args, incrementAndGetCounter(args));
            } catch (Exception ex) {
               //stuff
            }
        }
    }
}

Expected behavior
Our expectation is that onConsecutiveRun logic would be written to as actions to take on consecutive runs of the same handler, not a completely unrelated one. I would expect the ACTIVE_HANDLER to be a Map<string, rflib_TriggerHandler> where the string index is the handler class name.

Screenshots
If applicable, add screenshots to help explain your problem, i.e. Chrome Dev Console.

Desktop (please complete the following information):

  • OS: Windows
  • Browser n/a
  • Version n/a

Additional context
I understand that we could rewrite the onConsecutiveRun methods of all our handlers to run the functional logic but this would seem to reduce the value of having the framework in place. I am not sure if there is a value proposition for treating handlers across any object/operation as consecutive.

@j-fischer j-fischer added this to To Do in RFLIB-TF via automation Aug 7, 2021
@j-fischer
Copy link
Owner

@mikbranchaud Thanks for submitting this issue. It sounds like a legit bug. Let me do a closer review over the next couple weeks and once confirmed, work on a fix. I will probably tag you on the PR.

Cheers

@j-fischer j-fischer added this to the RFLIB-TF 1.4 milestone Aug 7, 2021
@j-fischer j-fischer added the bug Something isn't working label Aug 8, 2021
@j-fischer
Copy link
Owner

00521000007ooieAAA_2021-08-07T23_45_15Z_TID_11835790000da6aaed_CaseHandler.txt

Reproduced the issue. Attached is the log file of the test run that shows that the CaseHandler immediately ran the onConsecutiveRun method.

@j-fischer j-fischer linked a pull request Aug 9, 2021 that will close this issue
@j-fischer j-fischer moved this from To Do to In progress in RFLIB-TF Aug 9, 2021
@j-fischer
Copy link
Owner

@mikbranchaud Please see the attached PR for the fix. Would appreciate your review before I merge it to master and finalize the package. Thanks

RFLIB-TF automation moved this from In progress to Done Aug 9, 2021
@j-fischer
Copy link
Owner

j-fischer commented Aug 9, 2021

@mikbranchaud RFLIB-TF 1.3.1 has been published. Please note that it depends on RFLIB 2.6 or higher.
Thanks again for reporting this issue. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

2 participants