Testing That an Agent Never Reveals Another Customer's Data
このコンテンツはまだ日本語訳がありません。
Module 6 of 6 in the chapter Beyond the Record: Agents, chapter 20 of Securing Salesforce: Sharing and Visibility. Each module stands on its own.
The question this module answers: A service agent runs as one user for every customer it talks to. How do you make sure each customer only ever hears about their own records, and how do you prove it?
Knowing who it is isn’t a boundary
Section titled “Knowing who it is isn’t a boundary”Here’s the problem, in one line from Salesforce: when a service agent runs as its agent user, context variables such as the messaging session’s contact “are used to pass the customer’s identity to the agent, but they don’t control data access.” Without more configuration, the customer reaches every record the agent user can, so you have to limit data access yourself (Agent Execution Context and Data Access by Type (opens in a new tab), Salesforce Help, checked 2026-11-26).
Think about what that means with module 2’s agent user. It needs to read cases, so its access covers the cases of every customer the agent serves. The agent knows it’s talking to one of them. Knowing isn’t stopping. Ask it the right way, and it can read another customer’s case, because its user can.
The sharing model can’t fix this on its own. Every customer shares one agent user, so there’s no sharing rule that gives each one only their own records. The boundary has to be built into the actions.
Scope every action to the verified customer
Section titled “Scope every action to the verified customer”Salesforce gives the pattern, in three steps (same page):
- Verify first, and keep the result. “Pass verified customer IDs into the custom VerifiedCustomerId variable.” The standard Customer Verification subagents do it for you; otherwise, a custom action stores the ID once the customer has proved who they are.
- Scope every action to it. “Explicitly scope Apex classes and flows called by standard and custom agent actions to customer records (WHERE ContactId = VerifiedCustomerId).” Every query an action runs carries that filter. Not most of them. Every one.
- Keep unverified people away from the actions. “Create filters (VerifiedCustomerId is not None) to restrict access to subagents and actions to verified customers.”
Some standard actions already do it. Salesforce’s example: “the Get Cases for Verified Contact action calls a flow that looks up the customer’s contact ID, checks it against the VerifiedCustomerId variable, and uses the verified customer ID to scope its queries.” And then the sentence that turns into this module: “you should carefully test and customize each action to meet your security needs.”
Notice where the boundary now lives: in the code of each action. That’s why module 4 matters so much. A scoped query inside a without sharing class is still a scoped query. An unscoped query inside a with sharing class still returns every customer’s records the agent user can see.
The test plan: one more user
Section titled “The test plan: one more user”You already have the method. Chapter 13 tests every access rule by proving the positive and the negative, and starts with the null test: before anything is shared, the people who shouldn’t see a record see nothing. For a service agent, run the same tests through the agent, and add the agent user itself:
- The positive. A verified customer asks about their own case, order or delivery, and gets it.
- The negative. The same verified customer asks about someone else’s, by number, by name, by address, and gets nothing about it. Not a summary, not a hint that it exists.
- The null. An unverified visitor asks the same questions, and gets nothing that needs verification.
- The agent user itself. Check what it can read in Setup, as in chapter 13 module 4, so you know what’s at stake if an action’s filter is missing.
Write the plan before you test, per persona, as chapter 13 module 2 does for people. Then test again whenever an action is added or changed, because a new action is a new place the filter can be missing.
That’s the floor. Agents also get asked in ways people don’t: indirectly, in pieces, as a game. The Data Architect course has the adversarial list (Now Try to Break It). Use it after the sharing tests pass, not instead of them.
Steve Trucking: the Recipient’s tracking page
Section titled “Steve Trucking: the Recipient’s tracking page”This section is the course’s running example, Steve Trucking, an invented company.
A Recipient gets a link to a tracking page, with no login, and asks the agent, “Where’s my delivery?” The agent runs as its agent user, which has to read delivery records to answer anyone. So the boundary is the action. Once the Recipient is verified, the agent’s one action looks up that Recipient’s delivery and only that one, scoped by the verified ID. The Data Architect course designs the rest of this agent (Treat an Agent Like a Curious Human).
The tests write themselves from the three users above. A verified Recipient asks about their delivery: the answer. The same Recipient gives a neighbor’s address: nothing. Someone with the link but no verification asks for the delivery window: nothing that needs verification. And the agent user’s own access, checked in Setup, tells you what a missing filter would have exposed.
Watch it after go-live
Section titled “Watch it after go-live”Tests prove the design on the day you run them. Chapter 19 keeps watching: give the agent user its row in the monitoring plan, learn what normal looks like for it, and alert when it reads more records in a conversation than one customer could own.
What an architect decides here
Section titled “What an architect decides here”- How each service agent verifies a customer, and where the verified ID is kept.
- That every action a service agent can call scopes its queries to the verified customer, with no exceptions written down as “fine.”
- Which actions are filtered to verified customers only.
- The test plan: the positive, the negative and the null, plus the agent user’s own access, run before go-live and after every action change.
- The monitoring row that would notice an action whose filter went missing.
Beyond the exam: what AI changes. This is the newest version of an old problem. A customer portal with a page that forgot its filter leaked to whoever found the page. An agent with an action that forgot its filter leaks to whoever asks.
Explore
Section titled “Explore”- Agent Execution Context and Data Access by Type (opens in a new tab), Salesforce Help (checked 2026-11-26)
- Three Users: Prove the Positive and the Negative, chapter 13
- For the adversarial tests: Treat an Agent Like a Curious Human, Data Architect
