Sub topic 3
Why a data-changing action should ask first
This chapter explains why an Agentforce agent should get the user's approval before it runs an action that changes data. It assumes you know Salesforce objects and records, you know what an Agentforce agent is and how Agent Builder is used, and you have a basic understanding of Flow or Apex invocable methods.
Read actions and change actions
An Agentforce action is a Flow, an Apex invocable method, or a prompt template that the agent can run. Some actions only read. Others create, update, or delete records. The two groups carry different risk.
| Action type | Example | Effect if the agent gets it wrong |
|---|---|---|
| Read | Look up a case by number | The user sees the wrong answer and asks again |
| Change | Set a case status to Closed | A record holds a wrong value until someone notices |
| Delete | Remove a contact | Data may be hard to recover |
A wrong read costs a retry. A wrong change can sit in your org unnoticed and affect reports, automations, and customers.
How an agent can get it wrong
The agent picks an action and fills its inputs from the conversation. The language model does this by interpreting what the user wrote. That interpretation can fail in a few common ways.
- Misread request. The user says "close the case from Acme". The agent picks one of two open Acme cases.
- Wrong input value. The user says "mark it done". The agent sends
Done, but the picklist value isClosed. - Wrong target. The agent reuses a case Id from earlier in the conversation after the user has moved on to another case.
- Unintended request. The user was asking a question, such as "what happens if I close this case?". The agent treats it as an instruction.
The agent usually sounds confident in all four cases. The user does not see the inputs the agent chose unless the agent shows them.
Why a confirmation step helps
A confirmation step makes the agent state what it is about to do and wait for approval. This gives the user a chance to catch a mistake before the data changes.
A good confirmation does three things.
- It names the record that will change.
- It states the new value.
- It waits for a clear yes before the action runs.
Compare the two flows below.
Irreversible changes
Some changes are easy to undo. You can set a status back to its old value, provided you know the old value. Other changes are not.
- A delete may remove related data, and the recycle bin does not always hold what you need.
- An update can fire a Flow or trigger that sends an email, creates a task, or updates other records.
- An update overwrites the previous value, and field history may not track that field.
The side effects are the main concern. Setting a case to Closed in the Apex example from this tutorial is one line of data change, but an automation on the case could notify a customer. Reversing the field does not reverse the email.
Where the risk shows up in the action itself
The action definition tells you whether it needs confirmation. Look at the Apex action from the spine.
@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;
// ... builds and returns results
}The update toUpdate; line is a data change. Any Flow with a Create Records, Update Records, or Delete Records element has the same property. Mark these actions as candidates for confirmation during design, not after something goes wrong.
The description matters too. The agent reads the label and description to decide when to use the action. Saying "This modifies data" tells the agent, and the people who maintain it, what kind of action it is.
A quick check for each action
Ask these questions about every action you add to an agent.
- Does it create, update, or delete records, or trigger something that does?
- Could the agent pick the wrong record or value from the conversation?
- Is the result costly or hard to reverse?
If the first answer is yes and either of the others is yes, the action should ask first. The next chapter shows how to turn this on with the Require user confirmation setting.
Exercise
An agent has three actions: "Get Case Details", "Update Case Status", and "Delete Contact". Which need a confirmation step, and why? Name one way each of the chosen actions could go wrong.
Show answer
"Update Case Status" and "Delete Contact" need confirmation because they change data. "Get Case Details" only reads, so a wrong result costs a retry. Update Case Status could set the wrong case or a wrong status value, and could trigger automations such as customer emails. Delete Contact could remove the wrong contact, and the related data may be hard to recover.