mitchspano/apex-trigger-actions-framework

Update Parent or related records at once rather than doing multiple times from each triggeraction class

rohithbolla opened this issue · 1 comments

Hey @mitchspano

This is not an issue to report. Im trying to see if we could improve in this aspect.

This is in regards to updating Parent/related objects from 'after update' event in child. For eg. lets say there is a business logic, which is addressed in one of the triggeraction classes on Opportunity object. As per that, if an opportunity is updated for some reason, that should trigger update on Account.

In addition, there is another business logic, which is addressed in another trigger action class for the same Opportunity object. As per this one, if an opportunity is updated with another reason, it should trigger Account update, where the Account Trigger logic, if matches some criteria, should trigger email send.

Since, due to recursion check by idprocessed flag(if we check for count==1), second iteration of account trigger logic would fail and prevents email send. Instead, could all sObjects(accounts here) be consolidated to update at end of each trigger cycle, rather than allowing each business logic to perform dml? Please correct me if I miss something here.

Thanks for checking out the framework! You are correct that multiple SObjects registering updates to the same parent records could result in multiple DML operations if you're not careful. I would recommend using a strategy like the "Avoid Repeated Queries" section to use static variables or the singleton pattern to register updates, then have the final trigger action within the context perform the DML. Let me see if I can provide some clearer guidance on this within the README.