Sub topic 13
Permissions, Data Access, and the Einstein Trust Layer
This chapter assumes you know the Salesforce data model (objects, fields, records), have used Setup in Lightning Experience, and understand permission sets and profiles. It also assumes you have a general idea of what a large language model (LLM) is. You should have seen how a topic holds actions, from earlier chapters.
An agent that can read and change records is only safe if it cannot see or do more than the person it works for. This chapter explains whose permissions an action uses, what controls apply at each layer, and what the Einstein Trust Layer does to the data that goes to the LLM.
Two Different Questions
Security for agent actions answers two separate questions.
- Can this action touch this data? This is about Salesforce access control: object permissions, field-level security, sharing, and Apex sharing keywords.
- What happens to the data once it reaches the LLM? This is about the Einstein Trust Layer: masking, prompt handling, and the agreements with the model provider.
Keep them apart when you troubleshoot. A missing field in an answer is almost always the first question. A concern about customer data leaving Salesforce is the second.
Whose Permissions Does an Action Use?
The answer depends on how the agent is deployed. Agentforce agents come in two broad kinds.
- Employee-facing agents run in the Salesforce UI, for example in a side panel. Actions run as the logged-in user, so the user's profile, permission sets, and sharing apply.
- Service agents talk to customers or other outside users. They run as a designated running user that you choose when you set up the agent. Actions run with that user's access, not the customer's.
The second case needs care. A service agent's running user is usually an integration-style user, and you decide what it can read and change. Treat that user like any service account and give it the minimum access the topics require.
The agent's choice of action never widens access. The planner only picks from actions you added to a topic, and each action then runs under the access of the user described above.
The Layers of Access Control
An action passes through several checks. Each one can only narrow what is available.
| Layer | What it controls | Example effect on an action |
|---|---|---|
| Agent and topic setup | Which actions exist at all | A topic with no update action cannot change records |
| Agent access (permission set) | Which users may use an employee agent | A user without the agent permission cannot open it |
| Object permissions | Create, read, edit, delete on each object | Query Records on Opportunity fails if the user lacks Read |
| Field-level security | Visibility and editability of each field | A hidden field is missing from Get Record Details output |
| Sharing | Which records the user can see | Identify Record by Name only finds records the user can access |
| Validation rules and triggers | Data integrity on save | An update action fails if a validation rule rejects the value |
Two consequences are worth remembering.
- Results differ by user. Two people asking the same question can get different answers because their sharing and field access differ. This is correct behavior, not a bug.
- Write actions obey the same rules as manual edits. A validation rule that blocks a save in the UI also blocks the action. The agent receives an error and should report it, not pretend the update worked.
Custom Actions and Sharing
Standard actions follow the access rules above for you. Custom actions only do so if the code is written that way. The Apex example from this tutorial's plan declares public with sharing class OpenCaseCounter. The with sharing keyword makes the class respect the sharing rules of the running user, so the count includes only cases that user can see.
Be aware of what with sharing does not do. It enforces record sharing, but it does not enforce object permissions or field-level security by itself. A SOQL query can still read fields the user cannot see unless you add WITH USER_MODE or WITH SECURITY_ENFORCED. Here is the same query with user mode, which enforces object and field access as well as sharing:
List<AggregateResult> rows = [
SELECT AccountId acct, COUNT(Id) total
FROM Case
WHERE IsClosed = false AND AccountId IN :accountIds
GROUP BY AccountId
WITH USER_MODE
];A class declared without sharing runs with system-level record access and can expose data the user should not see. Avoid it in agent actions unless a reviewed design requires it.
What the Einstein Trust Layer Does
The Einstein Trust Layer is a set of controls that sits between Salesforce and the LLM. When an action produces data that goes into a prompt, the Trust Layer handles it before and after the model call. The main features are:
- Secure data retrieval and grounding. The prompt is grounded with data fetched under the user's permissions. Data the user cannot see does not enter the prompt.
- Data masking. Detected sensitive values, such as names, email addresses, and phone numbers, are replaced with placeholders before the prompt is sent. After the response returns, the placeholders are swapped back to the real values. Masking is pattern-based, so it is a safeguard and not a guarantee for every free-text field.
- Zero data retention. Under Salesforce's agreements with its model providers, prompts and responses are not stored by the provider or used to train its models.
- Toxicity detection. Responses are scored for harmful content, and results are logged.
- Audit trail. Prompts, responses, and feedback can be recorded in Data Cloud for review, if your org has this enabled.
Some of these depend on org setup. Masking settings, for instance, are configured by an admin, and the audit trail needs Data Cloud. Check your org's configuration instead of assuming that every feature is on.
Verifying Access in Practice
Check a topic's security by testing as the people who will use it, not only as an admin.
- Create a test user, or use an existing one, with the same permission sets as the target audience.
- Open the agent as that user (employee agents), or review the running user's permission sets (service agents).
- Ask for a record the user should not see. The agent should say it found nothing, or ask for clarification.
- Ask for a field that is hidden by field-level security. It should not appear in the answer.
- Ask for an update that violates a validation rule. The agent should report the failure.
- Compare with an admin's results to confirm the differences are the intended ones.
The testing chapter covers how to inspect each action call and its output. Use that to confirm that the failed step was an access error and not a bad input.
Common Errors
- Testing only as an admin. Admin access hides every permission gap. A topic that works for you may return nothing for your users.
- Over-permissioned running user. Giving a service agent broad access to avoid errors turns a configuration problem into a data exposure.
- Assuming the instruction is a control. A topic instruction such as "never show salary" guides the LLM, but it is not enforcement. Use field-level security for rules that must hold.
- Assuming masking covers everything. Masked values depend on detection. Sensitive data in long free-text fields may not be detected.
- Missing user mode in custom Apex.
with sharingalone leaves field and object checks unenforced. - Treating an empty result as "no data". An empty result may mean the user lacks access. Check permissions before concluding the record does not exist.
Exercise
A service agent's Query Records action returns the Annual Revenue field for every account, including ones the customer's own contact should not see. The topic instructions say "Never reveal Annual Revenue." Why is this setup unsafe, and what should you change?
Show answer
Instructions guide the LLM but do not enforce access. The service agent runs as its designated running user, and that user can read Annual Revenue, so the data reaches the agent and can leak. Remove read access to Annual Revenue for the running user through field-level security (and limit its object and sharing access to what the topics need). Then test with that user to confirm the field no longer appears in action output.
Exercise
An Apex custom action is declared with sharing and uses a plain SOQL query. A user without access to the Case field InternalNotes_c asks the agent a question, and the notes appear in the reply. What is the cause, and how do you fix it?
Show answer
with sharing enforces record-level sharing only. It does not enforce field-level security, so the query can read InternalNotesc. Add `WITH USERMODE (or WITH SECURITY_ENFORCED`) to the SOQL query so that object and field permissions apply, then retest as that user.