2

Trying to implement the popular Financialforce enterprise design patterns library, and not clear on if it provides baked in capability to prevent a trigger recursion. I've looked through the core classes for clues, re-read the docs and no clues so far. Given I dont have control over how the unit of work is initiated i.e. could be a batch job, and I know I need to make an update to records AFTER they hit the database, how would I prevent the recursion ? Should I just add a static var as per 'old' approach

Any suggestions would be most appreciated.

2 Answers 2

1

I don't believe the fflib has anything built in to prevent multiple runs of the trigger. You would likely just have to handle it as a static var somewhere in the trigger pattern in the 'old' way.

You could just add the firstRun static boolean in the domain class and set it in the triggerHelper constructor. Then you can have control over what gets run twice as well.

1
  • Cheers for that. Like the idea re firstRun ststic boolean so we shall consider this solved. Aug 31, 2016 at 7:32
2

The answer is no longer true about fflib

In 2016, Disabling trigger events in Domain layer was added

fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableAll(); // dont fire anything
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableAllBefore();
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableAllAfter();
 
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableBeforeInsert();
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableBeforeUpdate();
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableBeforeDelete();
 
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableAfterInsert();
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableAfterUpdate();
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableAfterDelete();
fflib_SObjectDomain.getTriggerEvent(YourDomain.class).disableAfterUndelete();

To enable, just call the inverse e.g. .enableAfterInsert(); etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .