Orchestrate Messages Between Packages in Salesforce

The “Core Package” in Salesforce is a shared dependency of two or more other packages. The core package is also core to decoupling communication between packages.

Because unrelated packages can access the Core Package, the Core can be used to orchestrate messages between them using interfaces. Start by abstracting an orchestrator

public class ClosingEventOrchestrator {
public static void orchestrate(List<Opportunity> opps){
for (ClosingEventConsumerSubscription__mdt flow : [SELECT ApexClass__c FROM ClosingEventConsumerSubscription__mdt ORDER BY Order__c]){
IClosingEventConsumer consumer = (IClosingEventConsumer)Type.forName(flow.ApexClass__c).newInstance();

The orchestrator class handles a Closing event. Now the classes that want to consume the event decide to be tied to it, not the classes that publish the event. This is done with an interface class.

public interface IClosingEventConsumer {
void consume(List<Opportunity> opps);

Custom metadata enables a configurable separation and decoupling between the packages.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store