Sub topic 8
Agent identity and access: agent user versus running user
This chapter assumes you know Salesforce permission sets, object and field access, and the basics of topics and actions. Every action an agent runs executes as some Salesforce user. Which user it is depends on the agent type. That choice decides what data the agent can read and change.
Two identities
A service agent runs as an agent user. This is a dedicated Salesforce user that you create for the agent. Customers who talk to it are usually not Salesforce users, so the agent needs an identity of its own. Whatever that user can access, the agent can access.
An employee agent runs as the running user, the employee who is chatting with it. The agent has no separate data permissions. It sees what the employee sees.
| Row | Service agent | Employee agent |
|---|---|---|
| Acts as | Agent user | Running user |
| Who sets access | Admin, through permission sets on the agent user | The employee's own profile and permission sets |
| Same answer for every person? | Yes, the agent user's access is fixed | No, results differ by employee |
| Main risk | Agent user has more access than the task needs | Instructions imply access the employee lacks |
Configuring the agent user
Treat the agent user like any integration user and apply least privilege.
- Create the agent user with a license that fits the agent type.
- Assign permission sets that grant only the objects and fields the topics need. An Order Status topic needs read access to Order, not edit access.
- Grant access to the Apex classes and flows that the agent's actions call. If you skip this, the action fails at run time.
- Review record sharing. The agent user sees only the records its role and sharing rules allow.
Why `with sharing` matters
Apex does not enforce record sharing unless you ask it to. The GetOrderStatusAction class from the topic spine declares with sharing, so its query respects the sharing of the identity running it. For a service agent that is the agent user. For an employee agent it is the employee. Without with sharing, the class would run in system mode and could return records the identity should not see. Field-level security is a separate check. If a class must honor it, add WITH USER_MODE to the query or use Security.stripInaccessible.
List<Order> orders = [
SELECT OrderNumber, Status
FROM Order
WHERE OrderNumber IN :orderNumbers
WITH USER_MODE
];Common errors
- Reusing an admin as the agent user. The agent then reads and changes far more than any topic needs.
- Testing a service agent as yourself. You see results through your own access, not the agent user's. Confirm behavior with the agent user's permissions.
- Assuming instructions limit access. A line such as "do not show salary data" guides the model. It does not block a query. Permissions do that.
- Expecting identical employee results. Two employees asking "show my open cases" get different lists. That is correct behavior.
Exercise
A service agent's Order Status action returns orders that belong to other accounts. The Apex class is declared without a sharing keyword. Name two things to check and fix.
Show answer
First, declare the class with sharing so record sharing applies to the agent user. Second, review the agent user's permission sets, role, and sharing rules, and remove access beyond what the topic needs. Instructions alone cannot fix this.