Sub topic 7
Action Types and When to Use Each
This chapter assumes you know what a topic is and that actions are the things an agent can run inside a topic. It also assumes you have a basic familiarity with Flow and Apex. Here you will compare the common action types and learn how to pick one.
What an action type is
An action is a unit of work the agent can call. The action type is the kind of Salesforce asset that does the work. The agent doesn't care much about the type. It reads the action's name, description, and inputs, then decides whether to call it. The type matters to you, because it decides how you build, secure, and maintain the action.
The common types
| Action type | Best for | Typical example |
|---|---|---|
| Flow | Declarative logic, record lookups, updates, approvals | Create a case, update a contact's address |
| Apex | Logic that is hard to express in Flow, bulk queries, callouts | Look up order status with custom matching rules |
| Prompt template | Generating text from record data | Draft a follow-up email from an opportunity |
| Standard action | Common tasks Salesforce already provides | Answer questions from a knowledge source, summarize a record |
| API or external service | Systems outside Salesforce | Check shipping status in a carrier system |
Names and availability of standard actions change between releases. Check Setup for the current list.
Choosing a type
Start with the simplest option that works.
- Use a standard action if one already does the job. You maintain nothing.
- Use a Flow if the work is a lookup, create, or update that an admin can read and change.
- Use a prompt template if the output is generated text grounded in record fields.
- Use Apex when Flow gets awkward: complex branching, bulk-safe queries, or custom callouts.
- Use an external service action when the data or the process lives outside Salesforce.
Apex as an action
An Apex action is an invocable method. The agent reads the method label and description, and the descriptions on each variable. These descriptions are the text the agent uses to decide whether to call the action and what to pass in.
public with sharing class OrderStatusAction {
public class Request {
@InvocableVariable(label='Order Number' description='The order number the customer provided' required=true)
public String orderNumber;
}
public class Response {
@InvocableVariable(label='Status' description='Current status of the order, or Not Found')
public String status;
}
@InvocableMethod(label='Get Order Status' description='Looks up the current status of an order by its order number')
public static List<Response> getStatus(List<Request> requests) {
Set<String> orderNumbers = new Set<String>();
for (Request r : requests) {
orderNumbers.add(r.orderNumber);
}
Map<String, String> statusByNumber = new Map<String, String>();
for (Order o : [SELECT OrderNumber, Status FROM Order WHERE OrderNumber IN :orderNumbers]) {
statusByNumber.put(o.OrderNumber, o.Status);
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
res.status = statusByNumber.containsKey(r.orderNumber) ? statusByNumber.get(r.orderNumber) : 'Not Found';
results.add(res);
}
return results;
}
}Three details make this action agent-friendly:
- The query runs once for the whole list, so it is bulk-safe.
- The class uses
with sharing, so record access follows the running user. - A missing order returns
Not Foundinstead of an error, so the agent can tell the customer rather than guess.
Common errors
- Vague labels. An action named "Process Data" gives the agent nothing to match against a request.
- Missing variable descriptions. The agent may pass the wrong value or ask the user the wrong question.
- Two actions that overlap. The agent may pick the wrong one. Make each description say what the action does and does not do.
- Apex without sharing. The action may expose records the user should not see.
Exercise
A customer asks the agent to draft a reply that summarizes their latest case. Which action type fits best, and why would you avoid Apex here?
Show answer
A prompt template fits best, because the task is generating text from record fields. Apex would add code to maintain for something a template already handles. Use Apex only if you need logic the template cannot express.
Exercise
Your Apex action returns an error when an order number is not found. What change helps the agent respond well, and why?
Show answer
Return a value such as Not Found instead of throwing an error. The agent can then tell the customer the order was not found and avoid guessing.