Sub topic 2
Action types and why you would choose Flow
An Agentforce agent can only change the world through actions. This chapter surveys the kinds of actions you can give an agent, compares them, and gives criteria for choosing Flow.
This chapter assumes you know the Salesforce data model (objects, fields, records) and Flow Builder basics (variables, elements, resources). It also assumes you can navigate Setup and permission sets, and that you know in general what an AI agent is. The previous chapter covered how agents, topics, and actions fit together. Here we only ask which kind of action to build.
What an action is
An action is a unit of work that the agent can call. Each action has a name, instructions, a set of inputs, and a set of outputs. The agent's language model reads those descriptions and decides whether to call the action, what to pass in, and how to use what comes back. The model does not see your flow's elements or your Apex code. It sees only the action's interface and descriptions.
Because the interface is what matters, several different implementations can sit behind the same shape: name, inputs, outputs. That is why Agentforce offers several action types.
The main action types
The list below reflects the types available in Agent Builder at the time of writing. Names and availability change between releases, so check the current Salesforce documentation when you plan real work.
| Action type | What runs behind it | Typical use |
|---|---|---|
| Standard action | Prebuilt logic that Salesforce supplies | Summarizing a record, drafting an email, querying records |
| Flow | An autolaunched flow that you build | Reading or updating records with admin-built logic |
| Apex | An Apex method annotated as invocable | Complex logic, bulk processing, custom calculations |
| Prompt template | A prompt template that you configure | Generating text grounded in record data |
| External service or API | A call to an outside API, often described by an OpenAPI schema | Reaching systems outside Salesforce |
Standard actions
Standard actions come with the platform. If one already does what you need, use it. You get tested behavior and no maintenance. The trade-off is that you cannot change the logic. You only configure what the action exposes.
Flow actions
A flow action wraps an autolaunched flow. Only autolaunched flows work here, because a screen flow needs a user interface and the agent has none. You build the flow with the same tools you already use: Get Records, Decision, Update Records, and so on. The flow's input variables become the action's inputs, and its output variables become the action's outputs.
Apex actions
An Apex action wraps a method marked with @InvocableMethod. The method takes a list of request objects and returns a list of result objects. Apex suits logic that is awkward in Flow: heavy computation, complex data structures, or code that needs unit tests and version control as ordinary source files.
Here is a small invocable method that does the same job as the flow described in the Topic Spine, returning a case's status.
public with sharing class GetCaseStatusAction {
public class Request {
@InvocableVariable(
required=true
description='The Case Number of the case to look up, for example 00001026.'
)
public String caseNumber;
}
public class Result {
@InvocableVariable(
description='The current Status of the case, or a short message if no case was found.'
)
public String caseStatus;
}
@InvocableMethod(
label='Get Case Status'
description='Returns the status of a case when given its case number.'
)
public static List<Result> getStatus(List<Request> requests) {
List<Result> results = new List<Result>();
for (Request req : requests) {
Result res = new Result();
List<Case> found = [
SELECT Status
FROM Case
WHERE CaseNumber = :req.caseNumber
LIMIT 1
];
res.caseStatus = found.isEmpty()
? 'No case was found with that number.'
: found[0].Status;
results.add(res);
}
return results;
}
}This shows the main structural difference. In Apex, the interface comes from annotations and inner classes. In Flow, it comes from variable settings, as the next section shows. The Apex version also runs a query inside a loop. That is acceptable for a single request, but a production version would need to bulkify it.
Prompt template actions
A prompt template action sends a template to the language model, filled in with record data or other inputs, and returns generated text. Use it when the output is writing, such as a summary, a reply draft, or a description. It is not the right tool for changing records or enforcing business rules.
External service and API actions
These call systems outside Salesforce. You describe the API, usually with an OpenAPI schema registered as an external service, and Salesforce exposes its operations as actions. Choose this when the data or the work lives somewhere else. You can also reach an external system from inside a flow, so a Flow action and an API action sometimes overlap.
What a Flow action looks like
A flow becomes usable as an action mainly through two settings on its variables: Available for input and Available for output. In flow metadata, those are isInput and isOutput. A description on each variable tells the agent what the value means.
<variables>
<name>caseNumber</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>true</isInput>
<isOutput>false</isOutput>
<description>The Case Number of the case to look up, for example 00001026.</description>
</variables>
<variables>
<name>caseStatus</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>true</isOutput>
<description>The current Status of the case, or a short message if no case was found.</description>
</variables>The Apex and Flow versions expose the same interface: one input, one output, and descriptions on both. The agent cannot tell them apart. Later chapters cover writing these variables and descriptions in detail.
Choosing between types
Start with the work the action must do, then match it to the cheapest type that does it well.
Treat this as a default, not a rule. Real projects mix types, and a later chapter covers combining flows with Apex, subflows, and prompt templates.
Reasons to choose Flow
- Admins can build and maintain it. Anyone who can build flows can change the action without a developer.
- It works directly with Salesforce data. Get Records, Update Records, and Create Records cover most record work with no code.
- You can debug it visually. Flow Builder's debug tool shows each element's inputs and outputs, which makes the agent's behavior easier to trace.
- Fault handling is built in. Fault paths let you return a message instead of a crash. This matters for agents, as the later error handling chapter explains.
- You can control the run context. A flow can run in user context or system context, so you can decide how much access the action gets.
- Deployment is familiar. Flows travel through the same change sets, packages, and source-based deployments as the rest of your metadata.
Reasons to avoid Flow
- Complex logic gets hard to read. Deeply nested decisions and loops become a maze in the canvas.
- Performance limits. Flows share governor limits with the rest of the transaction. Heavy work on large record sets is usually better in Apex.
- Testing is lighter. Apex has mature unit testing. Flow has its own testing tools, but they cover less.
- Complex data shapes are awkward. Large nested structures are easier to handle in Apex classes.
- Large diffs are hard to review. Flow metadata is verbose XML, so code review is slower than for Apex.
Common mistakes when choosing
- Reaching for Apex first. Developers often default to code. If the logic is a lookup and an update, Flow is faster to build and easier for the team to maintain.
- Building a screen flow. Screen flows need a user interface. Build an autolaunched flow instead, and move any user interaction into the agent's conversation.
- Using a prompt template to change data. A template produces text. It does not apply rules or update records reliably.
- Building what already exists. Check the standard actions before you build anything.
- Packing several jobs into one flow. Multi-purpose flows have long lists of inputs, which confuses the agent. The design chapter that follows covers single-purpose actions.
Summary of the decision
Prefer a standard action when one fits. Use a prompt template for generated text, and an API action for outside systems. For work on Salesforce data, use Flow when the logic is readable on a canvas and an admin should be able to maintain it. Use Apex when the logic is complex, high-volume, or needs strong testing.
Exercise
A support team wants an agent action that takes a case number, checks whether the case is open, and, if it is, sets a field called CustomerNotified_c to true. The logic is one lookup, one decision, and one update. Which action type do you choose, and why? Name one change to the requirement that would make you reconsider.
Show answer
Choose a Flow action. The work is a lookup, a decision, and an update on Salesforce data, which Get Records, Decision, and Update Records express clearly, and an admin can maintain it. Reconsider if the requirement grew to include heavy computation, large record volumes, or complex data structures, or if the team needs Apex unit tests for the logic. In those cases an Apex action with the same inputs and outputs would be a better fit.
Exercise
Why can a screen flow not be used as an agent action, and what do you build instead?
Show answer
A screen flow depends on a user interface to collect input and show results, and an agent has no such interface during a conversation. Build an autolaunched flow, with input variables available for input and output variables available for output, and let the agent collect values from the user in conversation.