Sub topic 1
How Agentforce actions run
Agentforce agents do work through actions. This chapter explains what an action is, how the agent chooses and runs one, and where a confirmation step can fit. Later chapters build on this model.
Prerequisites
This chapter assumes you have:
- Basic familiarity with Salesforce objects and records.
- Some awareness of what an Agentforce agent is and how Agent Builder is used.
- A basic understanding of Flow or Apex invocable methods.
You do not need to have built an agent yet.
What an action is
An action is a single unit of work that an agent can run. The agent's language model does not touch your data directly. It decides when to call an action, and the action does the work on the platform.
Agentforce supports several action types:
| Action type | What it runs | Typical use |
|---|---|---|
| Flow | An autolaunched Flow | Look up or update records with declarative logic |
| Apex | An Apex invocable method | Custom logic that Flow cannot express easily |
| Prompt template | A prompt template | Generate text, such as a summary or a draft reply |
Each action has a name, a description, inputs, and outputs. The agent reads the name and description to decide whether the action fits the user's request. It reads the input descriptions to decide what values it must collect.
How the agent chooses and runs an action
Actions belong to topics. A topic is a group of related instructions and actions for one kind of job, such as case management. The agent first picks a topic that matches the request, then picks an action inside that topic.
The flow of one request looks like this:
Two points matter for confirmation:
- The agent chooses the action from text. Names and descriptions steer the choice, so a vague description can lead to the wrong action.
- Once the inputs are filled in, the action runs. Nothing in this basic path stops to ask the user. Confirmation has to be added.
A concrete action
The Apex class below is an invocable method that updates a case. Agent Builder can register it as an action.
public with sharing class UpdateCaseStatusAction {
public class Request {
@InvocableVariable(required=true label='Case Id' description='The Id of the case to update')
public Id caseId;
@InvocableVariable(required=true label='New Status' description='The new value for the Status field, for example Closed')
public String newStatus;
}
public class Result {
@InvocableVariable(label='Message' description='Outcome of the update')
public String message;
}
@InvocableMethod(
label='Update Case Status'
description='Changes the Status field of one case. This modifies data.'
)
public static List<Result> updateStatus(List<Request> requests) {
List<Case> toUpdate = new List<Case>();
for (Request r : requests) {
toUpdate.add(new Case(Id = r.caseId, Status = r.newStatus));
}
update toUpdate;
List<Result> results = new List<Result>();
for (Request r : requests) {
Result res = new Result();
res.message = 'Case ' + r.caseId + ' set to ' + r.newStatus;
results.add(res);
}
return results;
}
}Read it as the agent would:
- The method label and description say what the action does. The description also says "This modifies data", which is a useful signal.
- The two required inputs,
caseIdandnewStatus, tell the agent it must collect both values before it can run the action. If the user says only "close the case", the agent should ask which case. - The
Resultclass is the output. The agent reads the message and uses it in its reply. - The class uses
with sharing, so the update respects the running user's record access.
Reading and changing actions
Not every action carries the same risk. An action that only reads data, such as a case lookup, can be run again with no harm. An action that creates, updates, or deletes records changes the org, and some of those changes are hard to undo. The next chapter covers how to spot these actions. For now, note that the agent treats both kinds the same way unless you configure otherwise.
Where confirmation fits
You can add a confirmation step at two points in the flow above, between collecting inputs and running the action:
- The action's Require user confirmation setting, which is configured in Agent Builder.
- Wording in the topic's instructions that tells the agent to ask first.
Later chapters cover both. They work best together, because the setting is enforced by the platform and the instructions shape how the agent words the request.
Common errors at this stage
- Vague descriptions. "Updates a case" does not say which field changes. The agent may pick the action for the wrong request.
- Missing input descriptions. Without them, the agent may guess values instead of asking.
- Assuming the agent will always ask. By default it runs the action once it has the inputs.
Exercise
In the path from user request to result, at which step does an action change data, and why is that step the right place to consider asking the user for approval?
Show answer
The data changes at the "Action runs" step, after the agent has picked the action and collected its inputs. At that point the agent knows exactly what will change but nothing has happened yet, so a confirmation here lets the user approve or cancel before any record is modified.
Exercise
The Update Case Status action has two required inputs. What does that tell the agent to do if a user only says "Close my case"?
Show answer
The agent must collect the missing Case Id before it can run the action, so it should ask the user which case they mean.