Sub topic 7
Designing actions so the confirmation is clear
This chapter assumes you know Salesforce objects and records, have used Agent Builder, and can read a Flow or an Apex invocable method. It covers how to design an action so the agent can ask a clear confirmation question before data changes.
Why design affects confirmation
The agent builds its confirmation question from what it knows about the action. That knowledge comes from the action's name, its description, and the labels and descriptions of its inputs. If those are vague, the question will be vague too. A user who sees "Run the update action?" cannot tell what will change. A user who sees "Set case 5001R00000AbCdE to Closed?" can decide.
The Require user confirmation setting controls whether the agent asks. Your design controls how useful the question is.
Name the action after what it does
Use a verb and the thing it changes. "Update Case Status" tells the agent and the admin exactly what happens. "Case Helper" or "Process Request" does not. Avoid one action that does several unrelated things, because the confirmation then has to describe all of them.
State in the description whether the action reads or modifies data. The Apex example below does this with the sentence "This modifies data." That sentence helps the agent treat the action as a change that deserves a check.
Expose the values that matter as inputs
A confirmation can only mention values the agent holds. If the action looks up the record or picks the new value internally, the agent cannot show it to the user beforehand. Make the important values explicit inputs instead.
Here is an invocable method with inputs designed for this purpose:
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;
}
}Note what the design gives the agent:
Case IdandNew Statusare required. The agent must have both values before it can run the action, so both are available for the confirmation question.- Each input has a description with an example. "for example Closed" shows the expected form of the value.
- The output
messagereports what was done, so the agent can confirm the result in plain terms after the update. - The class uses
with sharing, so the update respects the running user's record access.
Keep the scope narrow
An action that updates one field on one record is easy to summarize. An action that accepts a free-form field name and value can change anything, and its confirmation is harder to read. Prefer several narrow actions over one general one. A narrow action also makes it easier to decide which actions need the confirmation setting.
Checklist
| Design element | Weak | Clear |
|---|---|---|
| Action name | Case Helper | Update Case Status |
| Description | Works with cases | Changes the Status field of one case. This modifies data. |
| Input label | Value | New Status |
| Input description | (empty) | The new value for the Status field, for example Closed |
| Scope | Any field on any record | One field on one record |
What to do next
After you design the action, register it in Agent Builder and turn on Require user confirmation. Then test the conversation in the preview to check that the agent names the record and the new value before it acts. Later chapters cover that test.
Exercise
An action is named "Process Request" and has one input called "Value". It updates a field chosen inside the Apex code. Give two changes that would make a confirmation question clearer.
Show answer
Rename the action to say what it does, for example "Update Case Status", and describe in the description that it modifies data. Then expose the record Id and the new field value as separate required inputs with descriptive labels, so the agent holds those values and can name them when it asks the user to confirm.