Modular Flows + Agentforce for Smarter Automation

Embrace Modular Flows to Build Smarter Automation for Agentforce

By

Automation is one of our superpowers as Salesforce Admins, and modular flows make that power even stronger.

If you’ve noticed, flows are everywhere! Your flow-building expertise is key to preparing your company for Agentforce by creating custom flow actions for agents. However, as we shift toward building autonomous agents, we must rethink our approach from building massive flows to developing smaller, reusable utility flows, or what I call modular flows.

This mindset isn’t entirely new—if you’ve built subflows, you’re already familiar with the concept. Modular flows emphasize reuse and maintainability, making it easier to manage and enhance automation across your platform. When you build modular flows, you build for reuse and easier maintenance. Build smaller autolaunched flows that can be re-used in multiple places in the platform, whether in a screen flow action, as a subflow, or in a custom flow action that an agent will use. Who doesn’t love working smarter, not harder?

Let’s be honest. While building modular flows will save you time in the long run, the upfront designing stage will take some time so that your flows can be built for reuse. While they require more thought upfront, the payoff is significant: less duplication, streamlined testing, and more efficient maintenance.

If you’re new to building flows, planning modular flows might seem daunting at first, but it doesn’t have to be. Sketch out the overall process and identify areas where functionality can be reused. Break your process into smaller, distinct tasks. Identify tasks that are likely to be repeated in other automations. For example, tasks like retrieving data, updating records, or sending notifications are usual candidates for modularization. Once you identify those candidates, you can design flows that focus on just one of these tasks, ensuring they’re easy to invoke from other flows or components later.

As you get started, keep it simple: define clear inputs and outputs for each modular flow, and document how they’ll interact with other parts of your automation. Doing this will make it easier for you to scale your flows over time and minimize confusion as you add complexity to your flows. Modular flows aren’t just about reuse — they’re also about making maintenance easier as your automation evolves.

The Mochi Cupcakes scenario: automation in action

To illustrate, let’s take Mochi Cupcakes—my fictional company where reps process orders over the phone. Their reps need quick access to the customer’s last five cupcake orders to keep calls short and efficient. To help their reps be more productive, Mochi Cupcakes wants to automate their most common tasks—retrieving a customer’s five most recent cupcake orders. Automating this common task is a perfect use case for modular flows. Our solution is to build an autolaunched flow to retrieve the customer’s most recent cupcake orders.

Describes the example use case scenario for automation.

Three scenarios, one modular flow

When we reviewed the Mochi Cupcakes processes, we noticed the reps would need access to past cupcake orders in three different scenarios. Rather than build this three times, test it three times, deploy it three times, and eventually, maintain it three times, we’re going to create a single utility or modular flow to handle the retrieval of the customer’s five most recent cupcake orders. But before we create the flow, let’s think through whether an autolaunched flow will work in the three scenarios.

Streamlining the cupcake order process
To tackle this requirement, we will create a screen flow. We’ll use a flow action button to retrieve the recent orders. The action button passes a customer’s recordId to the modular flow, retrieves the orders, and displays them for quick cloning or reuse. ✅

Displaying cupcake orders on the customer record
For this requirement, we will build a screen flow on the Contact record page. Reps will see the latest orders as formatted text so the data is not overlooked. Here, the modular flow is invoked as a subflow. ✅

Powering Agents with a modular flow
Reps interact with Mochi Cupcakes’ AI agent, which will use a custom flow action to retrieve recent orders. Clear instructions and predefined inputs/outputs ensure seamless integration and enhanced efficiency. ✅

Let me show you how I created that modular flow and reused it in the three scenarios.

Key modular flow principles: inputs and outputs matter

The keys to modular flows success are your input and output variables. Understand what data you will need to pass into your flow and what data you will need from it. These are your inputs and outputs. Be judicious in what you set as available for input and output so you don’t have a long list of variables to weed through. You should only have that focused list of a few variables to work with.

To ensure your modular flows are both effective and reusable:

Define inputs and outputs clearly:

  • Inputs are variables passed into your flow.
  • Outputs are variables returned from your flow.
  • Use concise, focused variable lists to simplify implementation.

Match data types:
Ensure consistency between the invoking component and the flow. For example, a text input variable in your flow must align with the text data type in the invoking component.

Plan for reuse:
Build autolaunched flows with reusability in mind, and test across scenarios to refine functionality.

In the Mochi Cupcakes scenario, I created an autolaunched flow, its sole purpose to retrieve the customer’s most recent five cupcake orders. This flow would use the contactId input record variable to (1) gather the customer’s existing contact information, (2) gather the customer’s cupcake orders, (3) sort the cupcake orders and retain the most recent five, (4) assign the customer data to a customer record output variable, and (5) assign the most recent five cupcake orders to a cupcake record collection output variable.

Retrieve Cupcake Orders autolaunched flow in five steps.

For any data your autolaunched flow is expecting to receive into the flow from whatever invoked it, set the variable to Available for input.

Variable resource set to Available for input.

For any data your autolaunched flow is expecting to send back to whatever invoked it, set the variable to Available for output.

Variable resource set to Available for output.

Data types must match

Make sure the data type in both the component and autolaunched flow match. For example, if your autolaunched flow is expecting a text data type for the recordId, your component must pass the value into the autolaunched flow input variable which is also a text data type. Additionally, if the autolaunched flow is passing a record collection as the output variable, your component must be able to accept the flow’s output as a record collection.

Don’t forget to configure the respective input and output variables, if needed, in the component that invokes the autolaunched flow.

Scenario 1: Invoke the flow from an action button

Let’s step through how we’d invoke the modular flow in the first scenario—the cupcake order process. The animated gif illustrates the rep’s experience in creating the cupcake order. The Get Cupcake Info button is a flow action button that calls the autolaunched flow.

Screen flow that retrieves the customer’s five most recent cupcake orders.

In the cupcake order screen flow, we use a flow action button to call the autolaunched flow. In the action button, we pass the recordId from the customer lookup field into the autolaunched flow’s recordId input variable. When viewing the action button’s output variables, we see the autolaunched flow’s output variables.

Get Cupcake Info action button configuration in the screen flow.

Scenario 2: Invoke the flow from a subflow action

Let’s step through how we’d invoke the modular flow in the second scenario—where the Mochi Cupcakes rep sees the customer’s most recent five cupcake orders when viewing the customer’s contact record.

Customer’s contact record shows the five most recent cupcake orders with a screen flow component.

In this solution, I needed to gather the cupcake information and format it for display in a screen. So, I created a screen flow that (1) retrieved the five most recent cupcake orders using the autolaunched flow, (2) sorted the cupcake order record collection, (3) added the cupcake order information into a formatted text template, and (4) showed the formatted information in a screen.

Flow Builder screen shows Recent Cupcake Orders screen flow.

I used the subflow action as the first step of the screen flow to invoke my modular flow, i.e., autolaunched flow. Notice that I set the recordId input field of the autolaunched flow using a variable from my screen flow called recordId.

SortedCupcakeOrdersCollection output variable from the autolaunched flow is a record collection variable of the same name in my screen flow. This ensures that all data types match between the screen flow and autolaunched flows.

Flow builder screen shows recordId

The recordId variable in the screen flow is set to the “Text” data type, just like the input variable in the autolaunched flow.

Note: the variable resource is set to “Available for input” because the lightning record page where the flow component is placed will pass the recordId to the screen flow.

Edit Variable screen shows recordId variable in the screen flow.

The “SortedCupcakeOrdersCollection” record collection variable in the screen flow is set to the “Record” data type just like the sorted cupcake output record collection variable in the autolaunched flow. The variable resource is set to “Available for input” to receive the data from the autolaunched flow.

Edit Variable screen shows SortedCupcakeOrdersCollection record collection input variable in the screen flow.

Scenario 3: Invoke a flow from a custom Agent flow action

Lastly, let’s step through how we’d invoke the modular flow in the third scenario—where the Mochi Cupcakes rep interacts with the Mochi Cupcakes AI agent to get the customer’s most recent cupcake orders. In the animated gif, you will see the Mochi Cupcake rep asking the agent to recap Haley Atwood’s cupcake orders.

the Mochi Cupcake rep asking the agent to recap Haley Atwood’s cupcake orders

In this solution, we can reuse the modular flow that was used in our agent by creating a custom flow action and selecting our autolaunched flow: Retrieve Cupcake Orders.

The Create an Agent Action screen shows how we reference an existing action in Agent Builder.

Instructions are important to an agent. They provide clear guidelines for the agent, telling them when and how to perform specific actions within a conversation, ensuring consistent and accurate responses while minimizing errors, ultimately leading to a better customer experience and improved agent efficiency.

Notice the instructions for the agent action, inputs, and outputs are pre-populated. These are the descriptions from the flow itself.

Screen recording shows how to create a custom flow action in Agent Builder.

After creating the custom flow action, I updated the topic to include the recap of the cupcake orders in the Classification Description and Scope. I also created a new topic instruction, dictating what the agent should do if the user wants to recap cupcake orders including what to use as inputs and outputs of the specific flow action, specifying the output format, and what to do if the customer has no cupcake orders.

Agent instructions for summarizing the cupcake order.

Pro tips for modular flow success

  • Iterate to Improve: Modular flow building requires practice and iteration. Don’t hesitate to refine or split flows for better efficiency. Let’s be honest, implementing this new mindset does take some getting used to. I didn’t get it right the first time I tried this and after shifting to this mindset for some time, I still get it wrong. Sometimes, I think something will work and I get into building it and find that I can further chunk it down into a smaller flow or I run into a wall and discover I can’t handle it with an autolaunched flow.
  • Allocate Design Time: Plan extra time for upfront design to avoid rushed implementations. When I have more time to think it through and not rush to build something quickly, I build better modular flows. It requires iteration so plan for it. Make sure you factor the extra design time into your work effort estimation so you don’t shortchange yourself.
  • Learn from Limitations: Discover what works—and what doesn’t—by experimenting and evolving your approach. You may run into a wall and discover you can’t handle it with an autolaunched flow. For example, I thought I could use an autolaunched flow within a template-triggered prompt flow, but I learned that prompt flows only can be invoked as a subflow of other prompt flows. Perhaps that might change in the future. That’s ok. Get as much of the way as possible to minimize the number of flows performing the same function.

Your turn: build modular flows today

Take your flow-building skills to the next level by embracing modular design. Whether it’s for a screen flow, subflow action, or AI, modular flows simplify your org’s automation and prepare you for the future with Agentforce. Start small, iterate often, and watch your modular flow superpowers grow!

Resources

key 2024 takeaways for Salesforce Admins

Key 2024 Takeaways for Salesforce Admins: Agentforce, Flow, and More

As 2024 comes to a close, it’s time to reflect on all that Salesforce Admins have accomplished. ✅ This year was packed with innovation, and one of the standout milestones was the launch of Agentforce, Salesforce’s new suite of assistive and autonomous agents. With Agentforce, you can build, customize, and deploy intelligent agents tailored to […]

READ MORE
Build effective Agentforce agents

Build Effective Agentforce Agents for High-Impact Automation

As Salesforce Admins, we’re always looking for ways to automate processes and reduce manual work for our users. With the introduction of Agentforce, we have a powerful new tool that goes beyond traditional automation. Let’s explore how to create effective Agentforce agents that can handle complex tasks autonomously. This article is based on my session […]

READ MORE
Governance strategies for your first AI project

AI and Agentforce: Governance Strategies for Your First AI Project

There is a lot of excitement around artificial intelligence (AI) right now. New uses and new models are changing the way we think about how AI can support and improve the ways we work.  At Dreamforce ’24 one of the big announcements was Agentforce, a powerful companion to help Salesforce users resolve cases, answer questions, […]

READ MORE