Sub topic 2
Spotting actions that change data
This chapter covers how to look at an Agentforce action and decide whether it reads data or changes it. That decision determines which actions need a confirmation step. It assumes you know the basics of Salesforce objects and records, you have used Agent Builder at least once, and you can read a simple Flow or an Apex invocable method.
Why classification comes first
An agent's actions are the Flows, Apex invocable methods, and prompt templates that you attach to a topic. The agent reads each action's name and description, then decides which one to call. It does not run your Flow or Apex step by step. It calls the action as a unit and uses whatever comes back.
Before you can protect users from unwanted changes, you need a reliable list of the actions that can make them. Many actions are easy to classify. Others hide a write behind a harmless name, or trigger writes elsewhere in the org. This chapter gives you a method that works for all of them.
Reads, writes, and everything in between
Sort every action into one of three groups.
- Read-only. The action looks up or calculates something and returns it. Nothing in Salesforce or an outside system is different afterward.
- Data-changing. The action creates, updates, or deletes records, or otherwise alters stored state.
- Side-effecting. The action does not change a record directly, but it does something you cannot take back, such as sending an email or calling an external system that changes its own data.
The third group matters because "data" in this tutorial means more than Salesforce records. A message that has been sent cannot be recalled. A payment request that an external service has accepted cannot be undone by editing a field.
| Action behavior | Group | Example |
|---|---|---|
| Queries records and returns field values | Read-only | Get the status of a case |
| Calculates a value from inputs | Read-only | Estimate a renewal price |
| Creates a record | Data-changing | Log a new task |
| Edits fields on a record | Data-changing | Set a case to Closed |
| Deletes a record | Data-changing | Remove a draft quote |
| Sends an email or message | Side-effecting | Email a customer an update |
| Calls an external API that writes | Side-effecting | Submit a refund to a payment service |
| Generates text from a prompt template | Usually read-only | Draft a reply for the user to review |
Prompt templates deserve a note. A template produces text from instructions and merged record data. On its own it does not write anything. It becomes risky only when the agent or another action takes that text and saves or sends it. Classify the template as read-only, then classify the action that uses its output.
Reading a Flow
Open the Flow behind an action and look at its elements. The element types tell you most of what you need.
Elements that read:
- Get Records
- Decision
- Assignment, which changes only Flow variables
- Formula and Text Template resources
Elements that change data:
- Create Records
- Update Records
- Delete Records
Elements that can cause side effects:
- Action elements such as Send Email, Post to Chatter, or Submit for Approval
- Apex actions
- External Service actions
- Subflows
Two cautions apply to Flows.
First, an Assignment element can look like a write, but it only sets a Flow variable. It does not save anything. The record changes only when an Update Records element runs. Look for the element that saves.
Second, check every path. A Flow may read on one branch of a Decision and write on another. If any reachable path writes, treat the whole action as data-changing. For example, an "Update Contact Email" Flow might begin with a lookup and update the record only when the new address passes a check. The action is still data-changing.
A subflow counts as whatever it contains. Open each subflow, and open the subflows inside it. A parent Flow with no write elements of its own is not read-only if a nested subflow contains Update Records.
Reading an Apex invocable method
In Apex, writes happen through DML (data manipulation language) statements and their Database class equivalents:
insert,update,upsert,delete,undelete, andmergeDatabase.insert,Database.update,Database.upsert,Database.delete, and similar methods
A SOQL query ([SELECT ...]) only reads. Callouts to external endpoints, with Http or a named credential, are a separate case. They can change data outside Salesforce, so classify them as side-effecting unless you know the endpoint only reads.
Here is a read-only invocable method. It queries a case and returns its status, and it contains no DML.
public with sharing class GetCaseStatusAction {
public class Request {
@InvocableVariable(required=true label='Case Id' description='The Id of the case to look up')
public Id caseId;
}
public class Result {
@InvocableVariable(label='Status' description='Current value of the Status field')
public String status;
}
@InvocableMethod(
label='Get Case Status'
description='Returns the Status field of one case. This does not modify data.'
)
public static List<Result> getStatus(List<Request> requests) {
Set<Id> caseIds = new Set<Id>();
for (Request r : requests) {
caseIds.add(r.caseId);
}
Map<Id, Case> casesById = new Map<Id, Case>(
[SELECT Id, Status FROM Case WHERE Id IN :caseIds WITH USER_MODE]
);
List<Result> results = new List<Result>();
for (Request r : requests) {
Result res = new Result();
Case c = casesById.get(r.caseId);
res.status = (c == null) ? 'Case not found' : c.Status;
results.add(res);
}
return results;
}
}Compare it with the UpdateCaseStatusAction from the topic plan. That class builds Case records with a new Status and calls update toUpdate;. The update statement is what makes it data-changing, and its description says so: "Changes the Status field of one case. This modifies data."
Reading the code is not always enough. A method can call a helper class, and the helper can contain the DML. Search the whole call chain, not only the invocable method.
Hidden writes
Some actions look read-only and are not. Check for these four causes.
- Misleading names. A Flow named "Check Case Eligibility" might set a flag on the case as a side effect. Names reflect what the author intended on the day they wrote it. They do not guarantee what the action does now.
- Automation triggered by a write. An action that updates one field may fire record-triggered Flows, Apex triggers, or validation and assignment rules that change other records. The action's own logic can be a single update while the total effect is much larger.
- Nested logic. Subflows and helper classes can contain writes the top level does not show, as described above.
- Edits made after approval. An action that was read-only when you reviewed it can gain a write later. Re-check actions whenever someone edits the Flow or class, not only when you first add the action to the agent.
When you cannot tell, treat the action as data-changing until you have read the full chain. Wrongly adding a confirmation step costs the user one extra message. Wrongly omitting it can cost real data.
How the agent sees the action
The agent never sees your Flow elements or Apex code. It sees the action's name, its description, and its inputs. So the written description is the only place where the "this changes data" fact reaches the agent's reasoning. A confirmation setting on the action works whatever the description says, but the agent's wording to the user depends on the description.
State the effect plainly. Compare these two Apex descriptions:
- Weak:
Updates a case. - Better:
Changes the Status field of one case. This modifies data.
The better version names the object, the field, the scope (one case), and the fact that data changes. The same applies to Flow descriptions. Chapter 7 covers input and description design in full. For now, make writing the effect into the description part of your classification step.
A classification workflow
Use this sequence for each action you plan to attach to an agent.
- Open the underlying Flow or Apex class.
- List every element or statement that writes, including those inside subflows and helper classes.
- List every external call and email-style action.
- Consider the record-triggered automation that those writes would fire.
- Label the action read-only, data-changing, or side-effecting.
- Make sure the action's description says which one it is.
Edge cases
- Bulk input. Invocable methods receive a list. If the agent passes several records at once, one call can change many of them. Count the scope of a single call, not only the logic for one record.
- Create actions. Creating a record is a change even though nothing existing is overwritten. It may fire automation, consume a limit, or produce a duplicate that is hard to find later.
- Partial writes. A Flow that updates three records and fails on the third may leave the first two changed, depending on how the Flow handles faults. Note whether the action can leave a half-finished state.
- Standard actions. Actions that come built into Agent Builder are not exempt. Read the description of each one before you add it, and check which objects and fields it can touch.
- Permissions. An action that is data-changing in design may be unable to write for a particular user because of field-level security or sharing. Do not use that as the reason to classify it as read-only. Permissions are a separate safeguard, covered in a later chapter, and can change.
What to do with the result
After classification, you have a short list of actions that can change data. The next chapters cover why those actions should ask first and how to configure that. For read-only actions, you normally do not need a confirmation step. A confirmation on a harmless lookup adds friction without protecting anything.
Exercise
A Flow named "Review Account Health" has these elements: Get Records on Account, a Decision on the annual revenue, and a subflow called "Flag At-Risk Accounts". The Decision sends low-revenue accounts to the subflow. The subflow contains an Update Records element that sets a field named AtRisk_c to true. Is the action read-only or data-changing? Which agent-facing text should you change?
Show answer
It is data-changing. The subflow's Update Records element writes on a reachable path, so the whole action counts as data-changing even though the top-level Flow only reads and decides. Rewrite the action's description to say that it modifies data, for example "Reviews an account and sets the AtRisk_c field to true when revenue is low. This modifies data." Consider renaming the Flow too, because "Review" suggests a read. Then add a confirmation step for it.
Exercise
An Apex invocable method runs [SELECT Id, Status FROM Case WHERE Id IN :ids] and then calls a helper, CaseHelper.syncToBilling(cases). The helper makes an HTTP callout that posts the case data to a billing service. There is no DML in either class. How do you classify the action, and why?
Show answer
Side-effecting. Nothing in Salesforce changes, but the callout posts data to an external system that may create or change records of its own. You cannot assume it only reads. Confirm what the billing endpoint does. Unless you know it is read-only, treat the action as needing confirmation and say in the description that it sends data to the billing service.