Façade Pattern with Apex and Flow Actions: Simplifying Complexity in Salesforce

Recently, I had the pleasure of presenting at a Salesforce conference where I went into the practical application of the Façade Pattern using Apex and Flow Actions. For those who might not be familiar, the Façade Pattern is a structural design pattern that provides a simplified interface to a complex subsystem. Think of it as a way to streamline interactions by masking the intricate workings of a system behind a more user-friendly interface.

In essence, a façade is an interface that simplifies the complexities of a system. Imagine you’re using a universal remote control to operate your TV, DVD player, and sound system. Instead of juggling multiple remotes and figuring out how each device works, the universal remote provides a single point of interaction. Similarly, a hotel concierge offers guests a seamless way to access various services without needing to understand the intricacies of each one.

To illustrate how the Façade Pattern can be applied within Salesforce, I shared this class diagram during the presentation.

  • Invocable Method Class: Contains methods that can be called from Flow, making complex logic accessible through simple Flow actions.
  • Request Class: Represents the data that the Flow Designer provides to the InvocableMethod.
  • Result Class: Represents the data returned to the Flow Designer after the InvocableMethod completes its task.
  • API Interaction Classes: Handle interactions with an external system’s API, which the InvocableMethod class abstracts.

To truly embrace the façade pattern, you really need to plan and think about the Flow Designer experience using your Action. What is “just the right amount” of information that can be passed in between to allow the Action to be easy to use while being as flexible as possible?

  • Flow Actions for Pardot (available on AppExchange): A comprehensive suite of over 25 Flow actions that expose the Pardot API functionalities to Flow, allowing for really cool use cases.
  • MS Teams Notifications (available on AppExchange): Three Flow actions that enable sending notifications to Microsoft Teams channels, simplifying communication workflows.
  • Flow Actions for Harvest: An internal set of Flow actions designed to integrate with a time-tracking application, facilitating efficient time management within Salesforce.
  • Custom Company Applications: Various other internal applications where I’ve utilized this pattern to integrate proprietary company services into Salesforce Flows

To make the concept even more relatable, I walked through a specific use case: sending a swag package to a new employee. Here’s how the Façade Pattern was applied:

  • Swag.com API Integration: I showed how the swag.com API can be incorporated into Salesforce using the Façade Pattern.
  • Class Diagram Revision: We revisited the class diagram to see how this particular use case fits in.
  • Code Walkthrough: I provided a detailed walkthrough of the relevant code, demonstrating how to implement the façade.

Documentation, blog posts, and presentation examples all simplify (and remove) things that really need to be considered to have a robust solution in order to focus on the lesson. Recognizing this, I wanted to let the audience know that “this isn’t all there is”. Towards the end of the presentation, I offered some advanced tips to elevate the initial implementation:

  • Removing Hard Coded Ids: Replace hard-coded values with dynamic ones to enhance flexibility and maintainability.
  • Adding Error Handling: Implement robust error handling to manage potential issues gracefully.
  • Handling Large Volumes of Requests: Optimize the system to efficiently process large volumes of requests, ensuring scalability. (ok, maybe not so important when sending swag to onboarding employees)

The Façade Pattern is a great tool for Salesforce developers, enabling the creation of clean, maintainable, and scalable code. By abstracting complex subsystems behind a simple interface, developers can streamline their workflow and focus on delivering value. Whether you’re integrating with external APIs or developing internal applications, the Façade Pattern can significantly enhance your development process.

For those interested in implementing this pattern, I encourage you to start small, build on the basics, and gradually incorporate more complex functionalities.

Adam Erstelle is the Senior Technical Architect at Palladin Technologies. As a seasoned technology leader, he has a proven track record of delivering complex and innovative solutions while building successful engineering teams. With over two decades of experience in the technology sector, Adam brings a diverse skill set, deep expertise in web technologies, and a unique perspective on shaping technical strategies for both start-ups and established organizations.