Posts

Showing posts from May, 2019

Embracing Package-Based Development on the Lightning Platform: Separating Triggers into Multiple Packages

Image
Consider a case where you might want to have a package hierarchy. As an ISV or Consultant, you might create a package for an industry, and then one or more packages for each business unit under that industry. As a best practice, you should have a single trigger and trigger handler class per object. This allows you to control the order in which trigger operations can occur. Let's say you use the package hierarchy below: The tricky thing here is, while you will want to install the industryCommon package for every customer, the same isn't true for the child packages. For a given customer, you might want to install businessUnit1, businessUnit2, or both. Given the package hierarchy above, it's not possible to have a single trigger on the Contact object. That is, until we leverage the power of Interfaces and the Type class. To implement apex best practices, we will need to create a single trigger and trigger handler class in the industryCommon package. When we are