Sub topic 1
How Agentforce Actions Run
An Agentforce agent talks in natural language, but it changes your org by running actions. To decide where a confirmation step belongs, you need to know what an action is, how the agent picks one, and what happens between the user's message and the database write. This chapter covers that runtime path. Later chapters build on it to add confirmation.
Prerequisites
This chapter assumes you already have the following:
- Basic familiarity with Salesforce objects and records. You know what a Case is, what the
Statusfield does, and what an Id looks like. - Awareness of what an Agentforce agent is and how Agent Builder is used to configure one.
- A basic understanding of Flow or Apex invocable methods. You should be able to read a short Apex class and recognize an autolaunched flow.
You do not need to have built an agent action yourself.
What an action is
An action is a unit of work that an agent can run on a user's behalf. The agent itself only produces language and decisions. It cannot query, create, update, or delete records by itself. Every effect on your data or on another system goes through an action.
Actions come from several sources:
| Action source | What it runs | Typical use |
|---|---|---|
| Flow | An autolaunched flow | Look up an order, create a task, update a record |
| Apex | An invocable method | Logic that is hard to express in Flow, callouts, bulk work |
| Prompt template | A prompt template that calls the large language model | Draft an email, summarize a case |
| Standard action | A prebuilt action that Salesforce ships | Common tasks such as answering questions from knowledge |
Other action sources, such as external API integrations, also exist. The first three rows are the focus of this tutorial.
An agent can only do what its actions allow. An agent with no actions that write data cannot write data, however a user words the request. This is the basis of the safeguards in later chapters.
The runtime loop
When a user sends a message, the agent follows a loop. The exact internals belong to the Agentforce reasoning engine, but the observable steps are stable.
- The agent reads the user's message together with the conversation so far.
- It selects the topic that best matches the request. A topic groups related instructions and actions for one job.
- Within that topic, it decides whether an action is needed to respond, and which one.
- It collects the action's inputs. It takes values from the conversation, and when a required input is missing, it asks the user.
- It runs the action, which executes the flow, Apex method, or prompt template.
- It receives the action's outputs and writes a reply to the user based on them.
Two points follow from this loop and matter later.
- The agent chooses the action by reasoning, not by fixed rules. The same request can produce different wording from run to run, and an ambiguous request can select the wrong action.
- By default, nothing in the loop pauses before step 5. If the agent has the inputs it needs, the action runs and the data changes. Confirmation is something you add to this loop.
How the agent knows what an action does
The agent has no access to your flow's elements or your Apex code when it decides. It sees metadata: the action's name, its description, and the names and descriptions of its inputs and outputs. That text is the only basis for choosing the action and filling in its parameters.
This has practical consequences:
- A vague name such as "Process Record" gives the agent little to reason about. A specific one, such as "Update Case Status", does.
- A description should say what the action does, and for an action that changes data it should say so plainly.
- Input descriptions steer which values the agent extracts from the conversation. "The Id of the case to update" and "The new value for the Status field, for example Closed" tell the agent what to ask for.
In Apex, you provide this text through annotation attributes. In Flow, you provide it through the flow's label, description, and the descriptions on its input and output variables.
An example: an Apex action that changes data
The following invocable method updates the status of a case. It is a good example because the annotations are written for the agent as much as for developers.
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, then as an engineer.
What the agent sees. The action is called "Update Case Status". Its description says it changes one case and that it modifies data. It requires two inputs, a case Id and a new status, and each input has a plain-language description. It returns one output, a message, which the agent can use in its reply.
What the engineer sees.
- The
required=trueflag on both inputs means the agent must have both values before it can run the action. If the user says only "close my case", the agent has to find or ask for the Id. - The method takes and returns a
List, because Apex invocable methods must be bulk-safe. An agent usually sends one request at a time, but the signature stays the same. with sharingmakes the class respect record sharing rules for the running user. It does not enforce object or field permissions. Theupdatestatement here runs in system mode for those, so a user who could not edit theStatusfield through the UI could still change it through this action. Chapter on other safeguards returns to this.- The method does not validate
newStatus. If the agent passes a value that is not a valid status picklist value, theupdatethrows an exception and the action fails.
Where actions are attached: topics
An action does not float free. You add it to a topic in Agent Builder, and the agent can generally use it only when that topic is active. A topic carries a description, a scope, and instructions in natural language, together with the list of actions available for that topic.
This gives you two levers over behavior:
- Which actions exist in a topic. An action that is not assigned to the active topic is not available.
- What the instructions say. Instructions guide how the agent uses the actions in that topic, for example the order in which it should do things or when it should ask the user a question.
The next chapters in this tutorial use both levers. Topic instructions are covered in more detail later, and they are guidance to the model, not code. The agent usually follows them, but they are not a guarantee in the way a platform setting is.
What can go wrong
Understanding the runtime loop explains most surprises that occur with actions.
- Wrong action selected. Two actions with overlapping names or descriptions invite mistakes. The agent might pick a "Close Case" action when the user wanted to add a comment.
- Wrong input extracted. If the user mentions two case numbers in one conversation, the agent may pass the wrong one. Input descriptions reduce this risk but do not remove it.
- Misread intent. A user who writes "can you close that case?" may be asking a question, not issuing a command. An agent that treats it as a command runs the action.
- Action failure. A validation rule, a missing permission, or an invalid value makes the action throw an error. The agent receives the error and has to explain it. It does not know your data, so its explanation depends on the error message it gets.
- Partial or repeated work. If the user retries after an unclear failure, the action may run again. An action that is not idempotent, such as one that creates a record, can then produce duplicates.
All of these have the same effect when the action writes data: the change happens, and the user finds out afterward. For a read-only action, the cost is a wrong answer. For an action that updates or deletes a record, the cost is a changed or lost record. This is the motivation for the confirmation mechanisms in the rest of the tutorial.
Summary of the model
- Agents act on Salesforce only through actions: Flow, Apex invocable methods, prompt templates, and similar sources.
- The agent selects a topic, then an action, collects the inputs, runs the action, and replies from the outputs.
- It chooses and fills in actions from names and descriptions alone, so those texts are part of the design.
- Nothing in this loop asks the user for approval unless you configure it.
The next chapter looks at how to tell which of your actions read data and which change it, since that distinction decides where confirmation is needed.
Exercise
A user writes "Can you close case 5001R00000AbCdE?" and your agent has the Update Case Status action from this chapter in its active topic. Without any confirmation configured, describe what happens, and name two things in the action's metadata that influence whether the agent runs it correctly.
Show answer
The agent selects the topic, picks the Update Case Status action, extracts the case Id and the value Closed from the message, and runs the action right away, because all required inputs are present and nothing in the loop pauses it. The case Status changes before the user has approved anything, even if the user was only asking a question. The action's name and description (it changes the Status of one case and modifies data) influence whether the agent selects it. The descriptions of the inputs (Case Id and New Status, with an example value) influence whether the agent extracts the right values.
Exercise
The Apex class in this chapter uses with sharing. Does that guarantee a user without edit access to the Case Status field cannot change it through this action? Explain.
Show answer
No. with sharing enforces record-level sharing rules for the running user, but it does not enforce object permissions or field-level security. The update statement runs in system mode for those, so the change can succeed even if the user could not edit the field in the UI. Enforcing those permissions needs additional code, such as user-mode database operations, or other controls covered in a later chapter.