Sub topic 2
Spotting Actions That Change Data
This chapter assumes you know Salesforce objects and records, have used Agent Builder, and can read a simple Flow or Apex invocable method. Before you can decide which actions need a confirmation step, you need to sort your agent's actions into those that only read data and those that change it.
Read actions and write actions
An Agentforce action is a unit of work the agent can run, such as a Flow, an Apex invocable method, or a prompt template. Every action does one of two things to your org's data:
- A read action looks data up and returns it. It does not alter any record. Examples are fetching a case's status, listing open opportunities, or summarizing a knowledge article.
- A write action creates, updates, or deletes records, or triggers side effects outside Salesforce. Examples are closing a case, changing an opportunity stage, or sending an email.
Only write actions need a confirmation step in most designs. A wrong read costs the user a retry. A wrong write can change real data.
How to inspect an action
The label can mislead you, so check what the action does. Where you look depends on the action type.
| Action type | What to check | Signs of a write action |
|---|---|---|
| Flow | Open the Flow in Flow Builder and look at its elements | Create Records, Update Records, Delete Records, Send Email, or a call to a subflow or Apex action that does one of these |
| Apex invocable method | Read the method body | DML statements such as `insert`, `update`, `delete`, `upsert`, or `Database.*` calls, and callouts that post data to another system |
| Prompt template | Read the template and where its output goes | Usually read-only, since it generates text. It becomes a write path if a Flow saves its output to a record |
A Flow that only uses Get Records and returns values is a read action. A Flow with one Update Records element on a rarely used branch is still a write action. Look at every path, not only the main one.
A worked example
Here is the Apex invocable method used later in this tutorial.
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;
}
}The line update toUpdate; is a DML statement, so this is a write action. The method returns a message, but returning a result does not make an action read-only. What counts is whether data changes.
The description also says "This modifies data." The agent reads action descriptions when it chooses an action. A description that states the effect helps the agent, and it helps the person reviewing the action later.
Gray areas to watch
Some actions look like reads but are not.
- Hidden side effects. A "Get Customer Details" Flow might also stamp a "Last Viewed" field. Check every element, not just the name.
- Nested actions. A Flow can call a subflow or an Apex action. The write may be one level down.
- Outbound effects. Sending an email, posting to Slack, or calling an external API changes something outside Salesforce. You cannot roll these back with a record edit.
- Bulk effects. An action that accepts a list of records can change many at once. A single misunderstood request then has a larger reach.
- Creates. Creating a record can look harmless, but it can trigger automation, assignment rules, or notifications.
A simple audit routine
- List every action assigned to each topic in Agent Builder.
- Open each action's Flow or Apex class.
- Mark it read or write using the table above.
- For each write, note what it changes, whether you can undo it, and how many records it can touch.
- Keep the list. The next chapters use it to decide which actions get a confirmation step.
Write the word "modifies" or "creates" or "deletes" into the description of each write action. Later chapters show how clear descriptions help the confirmation message state exactly what will change.
Exercise
A Flow named "Get Order Summary" has a Get Records element, then a Decision element. One branch of the Decision runs an Update Records element that sets Order.LastChecked_c to today. Is this a read action or a write action, and why?
Show answer
It is a write action. The Update Records element changes a record whenever that branch runs, even though the Flow's name suggests it only reads. You must inspect every path in the Flow, not just the main one or the label.
Exercise
An Apex invocable method calls an external API with a POST request and does not use any DML. Does it count as a write action?
Show answer
Yes. A POST callout can create or change data in another system. It has no DML, but it still has an effect that you cannot undo by editing a Salesforce record, so treat it as a write action.