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

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

Open
rohithbolla opened this issue Mar 22, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@rohithbolla
Copy link

rohithbolla commented Mar 22, 2023

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.

@mitchspano
Copy link
Owner

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.

@mitchspano mitchspano added the enhancement New feature or request label Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants