I know from this blog post and this answer that a one trigger design pattern per object is ideal. Are there ever exceptions to that rule? If so, what are they?
Here is my situation to argue that there are exceptions to this rule, but I hope I'm wrong.
I have an AccountTrigger
, that then calls a class that makes a callout to an API, let's call this AccIntegrationUtility
. The AccountTrigger
also has other classes in it for modularity.
The AccIntegrationUtility
class is also used in a batch on the account object that runs nightly, lets call it AccountBatch
. The business requirement is they need to get third-party data when the account meets certain conditions during normal business hours and to get that same data for all accounts at 5am, before the business opens.
So I have the AccIntegrationUtility
class split between my AccountTrigger
and AccountBatch
.
I'm following sfdx on creating "artifacts", and they say you should have each artifact self contained. I want to create an artifact on the Account Integration, but the problem is the split. I don't want to have my entire AccountTrigger
and it's dependent class in my Account Integration artifact. What makes sense to me is to have two triggers, AccountTrigger
and AccountTriggerIntegration
. So, remove the integration from AccountTrigger
and place it all in the AccountTriggerIntegration
. That way I have an Account Integration artifact that doesn't need any of the other AccountTrigger
code, and can be tested on it's own and be in its own source. Thoughts?