Sub topic 3
What actions are and the types that exist
This chapter assumes you know the basics of the Salesforce data model, can move around Setup, and know that an agent uses a large language model (LLM) to interpret requests. It also assumes you've read the previous chapter on topics and instructions. Here you'll learn what an action is, how it runs, and which types you can attach to a topic.
What an action is
An action is a unit of work that an agent can run. The LLM can interpret a request and write text, but it can't read a record, change a field, or send an email by itself. An action does that work.
Each action has four parts:
- A name. The agent uses it to refer to the action.
- A description. The LLM reads this text to decide whether the action fits the user's request.
- Inputs. These are the values the action needs, such as an account name or a record ID.
- Outputs. These are the values the action returns, such as a record, a summary, or a count.
Under those four parts sits an implementation: something Salesforce already provides, or something you build. The implementation does the work. The LLM never runs it directly. The agent's runtime calls it and passes the result back.
How the agent uses actions at runtime
An action is available only when it belongs to the topic the agent has selected for the current request. The agent works through a loop:
- The agent classifies the user's message into a topic, using each topic's classification description.
- It reads that topic's instructions and the descriptions of its actions.
- It picks an action and fills its inputs from the conversation.
- The runtime executes the action and returns the outputs.
- The agent reads the outputs and either picks another action or writes a reply.
Two facts follow from this loop and explain many errors you will see later:
- The LLM chooses actions only from descriptions. If two actions have similar descriptions, the agent may pick the wrong one. If a description is vague, the agent may never pick it.
- Actions run only when the topic is selected. An action you built perfectly but attached to the wrong topic will never run for the requests you expected.
Action types
Actions are grouped by how they are implemented. The type decides who maintains the action and how much you can change it.
| Type | Implemented by | Typical use | Who maintains it |
|---|---|---|---|
| Standard | Salesforce | Query records, summarize a record, update a record, answer from Knowledge, draft an email | Salesforce |
| Flow | A Flow you build | Multi-step business logic, record changes with your own rules | You |
| Apex | An invocable Apex method | Logic that needs code, such as aggregate queries or callouts | You |
| Prompt template | A prompt template you build | A generated response grounded in your data, such as a custom summary | You |
Other types exist for calling external services through APIs. Which ones appear depends on your org and release, so check the options in your own Agentforce Builder.
Standard actions
Standard actions are prebuilt by Salesforce. You add them to a topic and configure them, but you don't write their logic. You can change their instructions and how their inputs are filled. The next chapters tour the catalog and show how to add each one.
Use a standard action when it already does what you need. It needs no code and gets maintained as the platform changes.
Custom actions
A custom action is any action you implement yourself. You write a Flow, an invocable Apex method, or a prompt template, and then expose it to a topic as an action. Once attached, it looks the same to the agent as a standard action: a name, a description, inputs, and outputs.
The agent can only understand the action through its description and the labels on its inputs and outputs. For Apex, you supply those with annotations:
public with sharing class OpenCaseCounter {
public class Request {
@InvocableVariable(label='Account Id' description='The account whose open cases are counted' required=true)
public Id accountId;
}
public class Result {
@InvocableVariable(label='Open Case Count' description='Number of open cases for the account')
public Integer openCases;
}
@InvocableMethod(label='Count Open Cases' description='Returns the number of open cases for an account')
public static List<Result> countOpenCases(List<Request> requests) {
Set<Id> accountIds = new Set<Id>();
for (Request r : requests) {
accountIds.add(r.accountId);
}
Map<Id, Integer> counts = 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
]) {
counts.put((Id) ar.get('acct'), (Integer) ar.get('total'));
}
List<Result> results = new List<Result>();
for (Request r : requests) {
Result res = new Result();
res.openCases = counts.containsKey(r.accountId) ? counts.get(r.accountId) : 0;
results.add(res);
}
return results;
}
}Three details in this class matter for agents:
- The
descriptionvalues are what the LLM reads. Without them the agent has little to go on. with sharingmakes the method respect the sharing rules of the user the agent acts for.- The method takes a list and returns a list, because invocable methods can receive several requests in one call. The result list must match the request list in order and size, which is why the code adds one
ResultperRequest, even when the count is zero.
Later chapters cover when to choose custom over standard. For now, treat the type as a decision about ownership and effort.
Actions read data, write data, or produce text
Another useful way to classify actions is by their effect. This matters more than the implementation type when you write instructions and think about risk.
| Effect | Example | Main risk |
|---|---|---|
| Reads data | Finding a record, querying records | Returning the wrong record or too much data |
| Writes data | Creating or updating a record | An unintended change to real data |
| Produces text | Summarizing a record, drafting an email | Inaccurate or off-tone content |
Actions that write data need the most care. A topic instruction can require the agent to restate the change and ask for confirmation before it runs a write action. This is the pattern from the sample topic below:
Topic: Account Support
Classification description:
Handle questions about a customer's account, such as looking up an account, summarizing it, or updating basic fields.
Instructions:
1. When the user names an account, first find the account record, then use the result for any later step.
2. Use the summary action when the user asks for an overview of an account.
3. Before updating a record, restate the field and the new value and ask the user to confirm.
4. If you cannot find exactly one matching record, ask the user to clarify instead of guessing.Each numbered instruction refers to an action by its purpose. Instruction 1 sets an order: find first, then use the result. Instruction 3 puts a confirmation step in front of a write. Instruction 4 stops the agent from guessing when a lookup is ambiguous.
Common errors
- Attaching an action to the wrong topic. The agent never offers it for the requests you tested. Check the topic's classification description and action list before debugging the action.
- Vague or duplicated descriptions. Two actions that both say "gets account information" make the choice unreliable. Write what each action does and when to use it.
- Assuming the action runs with elevated access. Actions run on behalf of the user. A user who can't see a record can't get it through an action. Chapter 13 covers this in detail.
- Treating the LLM as the executor. If a result looks wrong, the cause is usually the action's inputs, outputs, or implementation, not the model's wording.
- Writing instructions that name no order. When one action's output feeds another, say so, as in instruction 1 above.
Exercises
Exercise
A topic has two actions. Both have the description "Gets account information." Users report that the agent often picks the wrong one. What is the most likely cause, and what is the fix?
Show answer
The agent chooses actions by reading their descriptions, and these two descriptions are identical, so the choice is effectively arbitrary. Rewrite each description to say what the action returns and when to use it, for example one for finding an account by name and one for summarizing an account.
Exercise
You wrote an invocable Apex method that works in a test, but the agent never calls it for the requests you expect. Name two things to check on the agent side before changing the Apex code.
Show answer
First, check that the action is attached to the topic the agent selects for those requests. Second, check the action's description and input labels, because the agent decides based on them. A wrong topic or an unclear description keeps the action from being chosen even when the code is correct.