Sub topic 7
Action types and when to use each
An action is the unit of work an Agentforce agent can run. The previous chapters covered how a topic holds a set of actions and how the reasoning engine picks one. This chapter covers what sits behind an action. The kind of action you build affects how much control you have, how much it costs to maintain, and how well the agent can use it.
This chapter assumes you know what a topic and an action are, and that you have used Flow or Apex at a basic level. It also assumes you know that an LLM reads text descriptions to decide what to call.
The working model
Every action, whatever its type, presents the same face to the agent:
- A name and a description.
- A set of inputs, each with its own description.
- A set of outputs the agent can read back.
The reasoning engine never sees your Flow elements or Apex code. It sees that interface and chooses based on it. The action type decides what happens after the agent calls it.
This gives you a practical rule. Use deterministic logic (Flow, Apex, an API call) when the step must behave the same way every time. Use an LLM-backed action (a prompt template) when the step is about language, such as summarizing, drafting, or rephrasing.
The common action types
| Action type | What runs | Best for | Main risk |
|---|---|---|---|
| Flow | An autolaunched flow | Record lookups, updates, approvals, and logic an admin can maintain | Vague flow or variable descriptions |
| Apex | An invocable method | Complex logic, bulk queries, calculations, custom integrations | Needs developers and tests, and must be bulk-safe |
| Prompt template | A prompt sent to the LLM with merged record data | Drafting, summarizing, and classifying text | Output can vary, so it needs review |
| Standard action | A prebuilt action from Salesforce | Common tasks such as querying records or summarizing a record | Less control over behavior |
| API or external service | A call to an external system through a registered service | Data or operations outside Salesforce | Authentication, latency, and error handling |
The exact names and the list of standard actions change between releases. Check Setup for the current set in your org.
Flow actions
A Flow action wraps an autolaunched flow. Input variables marked "Available for input" become action inputs, and output variables marked "Available for output" become action outputs.
Flow is usually the first choice because admins can build, read, and change it without code. It also fits Salesforce data work well. Use it for steps like "find the order, check its status, return the status".
Common mistakes:
- Leaving variable descriptions empty. The agent then guesses what to pass in.
- Putting too many steps in one flow. An action that looks up data, updates a record, and sends an email is hard to describe, and the agent may call it when it only needs one of those things.
- Forgetting fault paths. If the flow fails without a clear error, the agent has nothing useful to tell the user.
Apex actions
An Apex action wraps a method marked @InvocableMethod. Choose it when Flow gets awkward: loops over large data sets, aggregate queries, custom parsing, or callouts you want to control tightly.
Treat invocable methods as bulk methods. They take a List of requests and return a List of responses in the same order, even if the agent only ever passes one request. The example below counts open cases for an account.
public with sharing class OpenCaseCountAction {
public class Request {
@InvocableVariable(label='Account Id' description='The Salesforce Id of the account to check' required=true)
public Id accountId;
}
public class Response {
@InvocableVariable(label='Open Case Count' description='Number of cases on the account that are not closed')
public Integer openCases;
}
@InvocableMethod(label='Get Open Case Count' description='Returns how many open cases an account has')
public static List<Response> getCount(List<Request> requests) {
Set<Id> accountIds = new Set<Id>();
for (Request r : requests) {
accountIds.add(r.accountId);
}
Map<Id, Integer> countsByAccount = new Map<Id, Integer>();
for (AggregateResult ar : [
SELECT AccountId acct, COUNT(Id) total
FROM Case
WHERE IsClosed = false AND AccountId IN :accountIds
GROUP BY AccountId
]) {
countsByAccount.put((Id) ar.get('acct'), (Integer) ar.get('total'));
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
res.openCases = countsByAccount.containsKey(r.accountId) ? countsByAccount.get(r.accountId) : 0;
results.add(res);
}
return results;
}
}The class uses with sharing, so the query respects the running user's record access. Keep that in mind for every Apex action. An agent that can read more than its user should is a security problem.
Prompt template actions
A prompt template action sends a template, filled in with record data, to the LLM and returns the generated text. It fits tasks where the output is language: a summary of a case history, a draft reply, or a product description.
Use it when you want to control the wording instruction and the data that goes into it, instead of letting the agent improvise. The template gives you a reusable, testable prompt.
Do not use it for facts the agent must get exactly right. A prompt template cannot reliably decide whether a refund is allowed. Put that decision in a flow or Apex action, then pass the result to a prompt template if you need it phrased well.
Standard actions
Standard actions are prebuilt by Salesforce for common work, such as querying records or summarizing a record. They save build time and are maintained for you. The trade-off is that you cannot change what they do inside. If your need is slightly different, a Flow or Apex action is usually easier than working around a standard one.
API and external service actions
Some actions call systems outside Salesforce, for example an order system or a shipping service. You register the API, handle authentication through a named credential, and expose the operation as an action. Decide early how you handle timeouts and error responses. The agent can only report what the action returns.
Choosing a type
The decision usually comes down to a few questions, asked in order.
Two rules of thumb sit on top of this path:
- Prefer the option the people maintaining it can read. A flow that an admin can open beats Apex that only one developer understands, if both do the job.
- Prefer deterministic logic for decisions and rules, and LLM-backed actions for wording.
How type affects action selection
The agent does not choose by type. It chooses by description. Two actions with different types but similar descriptions compete in the same way as two flows would. For example, a Flow named "Get Order Info" and a standard record query action may both seem to answer "where is my order?".
Keep your action set in a topic small and distinct:
- Give each action one clear job.
- Write descriptions that say when to use the action and what it does not do.
- Avoid pairing a general standard action with a narrow custom one for the same data unless the topic instructions say which to prefer.
Topic: Order Support
Instructions:
- To find the status of an order, use Get Order Status.
- Use Draft Delivery Update only after the status is known, and only if the customer asks for a written message.
Actions: Get Order Status, Draft Delivery UpdateHere one action is deterministic (a lookup) and one is a prompt template (wording). The instructions give them an order, so the agent does not use the writing action to guess a status.
Common errors
- Choosing by familiarity. Teams that know Apex build everything in Apex, which makes simple lookups harder for admins to change.
- Putting a rule inside a prompt template. A prompt can drift from your policy. Keep policy in Flow or Apex.
- One action doing many things. The agent cannot call half of it. Split it, and let the topic instructions say how to chain the parts.
- Mismatched outputs. If an action returns a raw JSON blob or an internal code, the agent has to interpret it. Return clear values such as "Shipped" or "Not Found".
- Ignoring permissions. Test actions as a user with realistic access, not as an administrator.
Exercise
A topic needs to (1) check whether a customer is eligible for a free replacement, based on order date and product type, and (2) write a friendly message explaining the result. Which action types would you use for each step, and why?
Show answer
Use a Flow or Apex action for step 1, because eligibility is a rule that must give the same answer every time. Choose Flow if an admin will maintain the rule and the logic is simple, or Apex if it needs complex or bulk logic. Use a prompt template action for step 2, because the task is writing text. Pass the eligibility result into the template as an input. Do not let the prompt template decide eligibility.
Exercise
Two actions in one topic are a standard record query action and a custom Flow called "Get Order Info". The agent keeps choosing the wrong one. What are two ways to fix it?
Show answer
First, rewrite the descriptions so each states a distinct job and when to use it, for example that the Flow is for order status by order number. Second, add a line to the topic instructions saying which action to use for order status. You can also remove one of the two actions from the topic if it is not needed.