Sub topic 10
Safeguards beyond confirmation
This chapter assumes you can build a basic Agentforce action with a Flow or an Apex invocable method, and that you have already turned on Require user confirmation for an action. It also assumes you know how permission sets and validation rules work in Salesforce.
Confirmation asks the user, "Do you want this change?" It does not check whether the change is allowed, whether the values are sensible, or whether the agent should have been able to reach the action. This chapter covers the controls that answer those questions.
What confirmation does not cover
Confirmation protects against one failure: the agent misread the request and the user would have objected had they seen the plan. Several other failures get past it:
- The user approves a bad change. People click "yes" quickly, especially when a summary looks routine.
- The agent runs with more access than the user. An approval then authorizes something the user could never do by hand.
- The inputs are valid text but invalid data. For example, the agent passes a status value your org never uses.
- The confirmation wording fails. Instruction-based confirmation depends on the model following your text. It usually does, but it is not a guarantee.
- The action is too broad. One action that updates any field on any object makes every confirmation summary vague.
The controls below address these. Most of them are enforced by the platform or by your code, not by the language model. That difference decides how much you can trust each control.
Controls enforced by the model and controls enforced by the platform
The model decides whether to follow topic instructions, so those instructions can be skipped or misapplied. The platform enforces permissions, validation rules and your own code on every call.
| Control | Enforced by | Stops | Can the model bypass it? |
|---|---|---|---|
| Confirmation wording in topic instructions | Language model | Unplanned changes the user would reject | Possible, because it is guidance |
| Require user confirmation setting | Agentforce runtime | Running the action without a user approval step | No, when the setting is on |
| Topic scope and action selection | Agent configuration | Reaching actions unrelated to the topic | Not for actions that are not assigned |
| Permissions on the running user | Salesforce platform | Reading or changing data the user cannot access | No |
| Input validation in the action | Your Flow or Apex | Values outside the allowed set | No |
| Validation rules and required fields | Salesforce platform | Records saved in an invalid state | No |
Treat the model-enforced rows as the layer that improves the experience. Treat the other rows as the layer that limits damage.
Run the action with the right permissions
An action runs as a specific user, and that user's access limits what the action can change. Check which user this is for your agent type:
- A service agent that talks to customers typically runs as a dedicated agent user that you configure. It does not run as the customer.
- An employee agent inside Salesforce typically runs in the context of the employee who is chatting.
Confirm this for your org and release in the Agentforce documentation, because the setup differs by agent type.
For an agent user, apply least privilege:
- Create a permission set for the agent that grants only the objects and fields its actions need.
- Give edit access only on the fields an action changes. If the action sets
Case.Status, the agent does not need edit access to every case field. - Do not grant "Modify All Data" or "View All Data" for convenience.
- Review the permission set whenever you add an action.
A common mistake is to build a broad permission set during prototyping and ship it unchanged. Then a confirmation prompt is the only barrier between the agent and data it should never touch.
Respect sharing and field-level security in the action
The action's own code can ignore the running user's access unless you tell it not to.
- In Apex,
with sharingapplies record sharing rules, but it does not enforce object or field permissions. AddWITH USER_MODEto queries andAccessLevel.USER_MODEto DML to enforce them. - In Flow, check whether the flow runs in user context or system context. A flow that runs in system context can change records the user could not change. Use system context only where you have a reason, and document it.
Validate inputs inside the action
The agent fills action inputs from the conversation. The model can supply a value that looks plausible but does not match your data model. Validate inputs in the action, and return a clear message when you reject one. The agent can then explain the problem to the user.
Useful checks:
- Allowed values. Compare picklist-style inputs against an explicit set.
- Record state. Refuse to change a record that is already in a final state.
- Batch size. An invocable method receives a list. Cap how many records one call may change.
- Existence and access. Query with user permissions, so a record the user cannot see is reported as not found.
The Apex class below hardens the UpdateCaseStatusAction from earlier in this tutorial. It keeps the same inputs and adds an allowed-status list, a batch cap, a record-state check and user-mode access.
public with sharing class UpdateCaseStatusAction {
private static final Set<String> ALLOWED_STATUSES =
new Set<String>{ 'Working', 'Escalated', 'Closed' };
private static final Integer MAX_REQUESTS = 5;
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='One of: Working, Escalated, Closed')
public String newStatus;
}
public class Result {
@InvocableVariable(label='Success' description='True if the case was updated')
public Boolean success;
@InvocableVariable(label='Message' description='Outcome of the update or the reason it was refused')
public String message;
}
@InvocableMethod(
label='Update Case Status'
description='Changes the Status field of up to 5 open cases. This modifies data.'
)
public static List<Result> updateStatus(List<Request> requests) {
List<Result> results = new List<Result>();
for (Request r : requests) {
results.add(refuse('Not processed'));
}
if (requests.size() > MAX_REQUESTS) {
for (Result res : results) {
res.message = 'Too many cases in one request. The limit is ' + MAX_REQUESTS + '.';
}
return results;
}
Set<Id> caseIds = new Set<Id>();
for (Request r : requests) {
caseIds.add(r.caseId);
}
Map<Id, Case> existing = new Map<Id, Case>([
SELECT Id, Status, IsClosed
FROM Case
WHERE Id IN :caseIds
WITH USER_MODE
]);
List<Case> toUpdate = new List<Case>();
List<Integer> positions = new List<Integer>();
for (Integer i = 0; i < requests.size(); i++) {
Request r = requests[i];
if (!ALLOWED_STATUSES.contains(r.newStatus)) {
results[i].message = 'Status "' + r.newStatus + '" is not allowed.';
} else if (!existing.containsKey(r.caseId)) {
results[i].message = 'Case ' + r.caseId + ' was not found or is not accessible.';
} else if (existing.get(r.caseId).IsClosed) {
results[i].message = 'Case ' + r.caseId + ' is already closed and cannot be changed.';
} else {
toUpdate.add(new Case(Id = r.caseId, Status = r.newStatus));
positions.add(i);
}
}
if (!toUpdate.isEmpty()) {
List<Database.SaveResult> saves =
Database.update(toUpdate, false, AccessLevel.USER_MODE);
for (Integer j = 0; j < saves.size(); j++) {
Result res = results[positions[j]];
if (saves[j].isSuccess()) {
res.success = true;
res.message = 'Case ' + toUpdate[j].Id + ' set to ' + toUpdate[j].Status;
} else {
res.message = saves[j].getErrors()[0].getMessage();
}
}
}
return results;
}
private static Result refuse(String message) {
Result res = new Result();
res.success = false;
res.message = message;
return res;
}
}Three details matter here:
Database.update(..., false, ...)allows partial success, so one bad record does not roll back the others. The method reports each outcome separately.- A refused request returns a message instead of throwing an exception. The agent can read the message and tell the user what went wrong.
- Results stay in the same order as the requests, so each message belongs to the right case.
Let validation rules do their job
Validation rules, required fields and Flow-based record-triggered checks run when the record is saved. They apply to the action just as they apply to a user editing a record. This gives you a place to state business rules once, for every entry point.
For example, a validation rule that blocks closing a case without a resolution note protects the record whether the change comes from a page layout, an import or an agent. If the agent hits the rule, the save fails and the error text comes back to the action. Write error messages for a person to read, because the agent may relay the text to the user.
Validation rules do not replace input checks in the action. A rule can tell you the final record is invalid, but it cannot tell you the agent asked for the wrong thing.
Keep actions narrow
The shape of an action determines how much a single approval can authorize. Compare two designs:
- Narrow: "Update Case Status" changes one field on one object, within an allowed set of values.
- Broad: "Update Record" takes an object name, a field name and a value, and changes whatever is requested.
The broad design is flexible, but it makes every safeguard harder:
- The confirmation summary has to describe an arbitrary change.
- Permissions must allow edits wherever the action might point.
- Input validation cannot list the allowed values.
- Testing has no finite set of cases.
Prefer several narrow actions. Give each a name and description that state exactly what changes, and say in the description that it modifies data. Separate read actions from write actions, so you can leave confirmation off for a lookup and keep it on for an update.
Limit what a topic can reach
A topic gives the agent a set of actions for one kind of job. Assign an action only to the topics that need it. If the "Order Status" topic only answers questions, do not add a cancel-order action to it. An action that is not available in the topic cannot be chosen there, whatever the user asks.
Keep topic instructions specific about scope too. Say what the topic covers and what the agent should do when a request falls outside it, such as handing off to a person.
Review what happened
Safeguards reduce risk, but you also need to see what the agent actually did. After release:
- Check the agent's session and conversation records available in your org to see which actions ran and with which inputs. The exact tooling depends on your edition and release, so confirm what is available to you.
- Write meaningful messages from your actions. They show up in those records and explain why a call succeeded or failed.
- Review the agent user's permission set on a schedule, and when you add actions.
- Rerun your conversation preview test cases after any change to an action, topic or permission set.
Choosing the right mix
Match the strength of the control to the cost of a mistake.
| Action | Example | Suggested controls |
|---|---|---|
| Read only | Look up case status | Permissions, narrow scope. No confirmation needed. |
| Low-impact, easy to undo | Add an internal note | Narrow action, validation. Confirmation optional. |
| Changes important data, reversible | Update case status | Require user confirmation, instruction wording, input checks, least-privilege permissions. |
| Hard to undo or high cost | Delete a record, issue a refund | All of the above, plus tight value limits, and consider a human approval step outside the chat. |
For the last row, a confirmation in the chat may not be enough. A refund above a threshold might create an approval request for a manager and not run immediately. The action then does not complete the change itself, which removes the question of whether the user's "yes" was well considered.
Summary
Confirmation catches misunderstood requests. Permissions limit what the action can reach, input checks reject unreasonable values, and validation rules protect the record. Narrow actions keep each approval meaningful, and review of the agent's activity shows you whether the controls work. Combine them in proportion to the damage a wrong change could cause.
Exercise
An agent action "Update Record" takes an object name, a field name and a new value, and has Require user confirmation turned on. The agent user has a permission set with edit access to all objects. Name three problems with this design and say how you would fix each.
Show answer
(1) The action is too broad, so the confirmation summary cannot describe a specific change and input checks cannot list allowed values. Replace it with narrow actions, such as "Update Case Status", each with a defined field and allowed values. (2) The permission set is too broad, so a mistaken or approved change can reach data the agent never needs. Reduce it to a least-privilege permission set with edit access only on the objects and fields the narrow actions change. (3) Nothing in the action validates inputs, and the action may bypass the user's access. Add allowed-value checks, a record-state check and a batch cap, and use user-mode queries and DML so object and field permissions are enforced.
Exercise
Why is a validation rule on Case a better place to enforce "a case cannot be closed without a resolution note" than a sentence in the topic instructions?
Show answer
The platform runs the validation rule on every save, whether the change comes from the agent, a page layout or an import, and the model cannot skip it. A topic instruction only guides the model's behavior and can be ignored or misapplied. The rule also protects the record when the model does something unexpected.
Exercise
In the hardened Apex action, why does the method return a Result with a message when a check fails, instead of throwing an exception?
Show answer
A returned message reaches the agent as normal action output, so the agent can explain the problem to the user and suggest a next step. An unhandled exception tends to produce a generic failure with less useful detail. Returning one Result per request, in order, also lets a batch report partial success clearly.