Sub topic 6
Sharing Rules and Field-Level Security for Agents
This chapter assumes you know Salesforce users, profiles, and permission sets, and that you understand objects, fields, and record sharing. It covers what an agent can see after its permission sets are in place.
Two layers of access
A permission set decides which objects and fields the agent user can work with. It does not decide which records. Record access is a second layer, and an agent is subject to both.
| Layer | Question it answers | Controlled by |
|---|---|---|
| Object permissions | Can the user read this kind of record? | Permission sets, profile |
| Field-level security (FLS) | Can the user see this field? | Permission sets, profile |
| Record sharing | Can the user see this particular record? | Org-wide defaults, role hierarchy, sharing rules, teams, manual shares |
A record is visible to the agent only when all three layers allow it. If the agent user has Read on Order and Order.Status, but sharing hides an order, the agent still cannot see it.
Sharing applies to the agent user
For an agent that runs as a dedicated agent user, sharing is evaluated for that user. Check these settings for the agent user:
- Org-wide default. If Order is Private, the agent user sees only orders it owns or that are shared with it.
- Role. A role placed high in the hierarchy can see records owned by users below it. Place the agent user deliberately, and avoid a role that grants broad visibility.
- Sharing rules. A rule that shares records with a public group or role can include the agent user. Review which groups the agent user belongs to.
- View All and Modify All. These permissions skip sharing for an object. Leave them off for the agent user, as the permission set in the previous chapter does.
For an agent that runs as the logged-in user, sharing is evaluated for that person. The agent sees what the person would see, so you do not need to design a separate record scope.
Field-level security limits what a field reveals
FLS works per field. The permission set from the earlier chapter gives the agent Read on Order.Status only. Other fields on Order, such as TotalAmount or BillingAddress, stay hidden unless you grant them.
This matters for two reasons:
- The agent cannot repeat data it never receives. Hiding a field is stronger than telling the agent in its instructions not to mention it.
- A field you grant is available to every action that runs as that user, not only the action you had in mind.
When you add a field to a permission set, ask which topic needs it. If none does, leave it out.
Where enforcement can fail
Standard actions, such as record lookups, respect these rules. Custom code needs care. Apex runs in system mode by default and ignores the user's object permissions and FLS. Apex declared without sharing also ignores sharing. An action built this way can return data the agent user could not otherwise read. A later chapter shows how to prevent this with with sharing and WITH USER_MODE.
Common errors:
- Granting View All Data for convenience. It removes sharing for every object.
- Reusing an existing service user. That user may already hold broad access from earlier projects.
- Testing as an administrator. Admins see almost everything, so a test passes even when the agent user would be blocked.
- Confusing silence with security. An empty answer can mean the record is hidden, or that the order number was wrong. Check both.
Verify the effective access
Use Login As for the agent user, or review its permission sets, and open a record you expect to be hidden. Then run the same request through the agent. The two results should match.
Exercise
The agent user has Read on Order and Order.Status. Org-wide default for Order is Private, and the user owns no orders. A customer asks about order 00001234. What does the agent see, and which two changes would expose more than intended?
Show answer
The agent sees nothing, because Private sharing hides records the user does not own or have shared access to. Granting View All on Order, or adding a sharing rule that shares all orders with a group containing the agent user, would expose every order. Grant narrower access, such as a criteria-based sharing rule, only if the use case needs it.