Sub topic 9
Choosing between Flow, Apex, prompt template, and standard actions
This chapter assumes you know what a topic is, can read basic Flow and Apex, and have seen how an action appears in a topic. Here you learn how to pick the right action type for a task.
What an action type is
An action is something the agent can do. Each action runs one underlying piece of logic. The action type names what that logic is. Agentforce Builder offers four common types:
- Flow: runs an autolaunched Flow you build with clicks.
- Apex: runs an invocable Apex method you write in code.
- Prompt template: sends a prompt to a large language model and returns the generated text.
- Standard action: a ready-made action that Salesforce provides, such as looking up or summarizing a record.
The agent does not care how the logic works. It sees the action's name, description, inputs, and outputs, and decides when to call it.
Comparing the four types
| Type | Best for | Main strength | Main cost |
|---|---|---|---|
| Flow | Record lookups, updates, and multi-step business logic | Admins can build and maintain it without code | Complex branching and loops get hard to read |
| Apex | Logic that Flow cannot express cleanly, such as heavy calculation or callouts with custom handling | Full control and unit tests | Needs a developer and deployment |
| Prompt template | Writing or summarizing text, such as an email draft or case summary | Grounds a model on record data | Output is generated text, not a data change |
| Standard action | Common tasks Salesforce already covers | No build work | Limited customization |
A decision order
Work through these questions in order. Stop at the first match.
- Does Salesforce already provide a standard action for this task? Use it.
- Is the result generated text based on record data? Use a prompt template.
- Can an autolaunched Flow do it? Use a Flow.
- Otherwise, use invocable Apex.
Flow comes before Apex because an admin can change it later without a deployment. Choose Apex when you need something Flow handles poorly.
Worked example
Take the Order Status topic. The task is to look up an order by its number and return its status.
- A standard action does not fit, because the lookup is specific to your order data.
- The output is a status value, not generated text, so a prompt template does not fit.
- A Flow with a Get Records element can do it. A Flow is the simplest choice.
- Apex is the better choice if you need extra rules, such as running the query in user mode and returning exactly "Not found" for a missing order.
Now take a different task: write a friendly summary of an order's history. The output is generated text, so a prompt template fits.
Common mistakes
- Using Apex by default. It adds deployment work that a Flow would avoid.
- Using a prompt template to change data. Templates produce text. They do not update records.
- Ignoring permissions. Whatever the type, check that the running user can access the data. Apex should use
WITH USER_MODEorwith sharing. - Vague action descriptions. The agent picks actions from their descriptions. Two actions with similar descriptions cause wrong picks, whatever their type.
Exercise
A topic must draft a polite reply to a customer, using the customer's open case details. The reply is text only, and no record changes. Which action type fits, and why?
Show answer
A prompt template. The result is generated text grounded on record data, and nothing needs to be updated. A Flow or Apex would only be needed if the agent had to change data or run custom logic.
Exercise
You need an action that updates a case status and also calls an external system with custom retry handling that Flow cannot express. Which type do you choose?
Show answer
Invocable Apex. Flow cannot express the custom retry handling, and Apex gives full control and unit tests. A standard action or a prompt template would not cover the update or the callout.