Sub topic 6
Assigning permission sets
This chapter covers the permission sets that let you build, test, and run an agent in your Developer Edition org. It assumes you can navigate Setup, know the difference between a profile and a permission set, and have enabled Agentforce in the previous chapters. The optional CLI steps need the Salesforce CLI and the agentforce-dev alias from the sign-up chapter.
Why permissions are a separate step
Turning on Agentforce in Setup does not mean you can use it. Three different identities touch an agent, and each needs its own access:
- The builder. This is you, the admin who opens Agentforce Builder and edits topics and actions.
- The agent user. For a service agent, this is a dedicated user that the agent runs as. Everything the agent reads or changes happens under this user's permissions and sharing.
- The end user. This is the person who chats with an employee-facing agent. Such an agent acts with that person's access.
Most "the agent can't see anything" problems come from granting access to the wrong identity.
Permission sets you will meet
Salesforce ships permission sets that are created or made available when you enable Agentforce features. Names and contents change between releases, so confirm them in your org: go to Setup > Permission Sets and search for "Agentforce", "Einstein", and "Prompt".
| Purpose | Typical permission set | Who gets it |
|---|---|---|
| Build and manage agents in the builder | An Agentforce admin set, such as Agentforce Default Admin | You, the builder |
| Create and edit prompt templates | Prompt Template Manager | You, if you use Prompt Builder |
| Run prompt templates | Prompt Template User | Users who invoke templates |
| Run as the service agent | An Agentforce service agent set, assigned to the agent user | The agent user |
| Reach your own Apex and data | A permission set you write | The agent user and any end user |
The last row matters most. Salesforce does not know about your custom Apex class or about which Case fields you want exposed. You grant that yourself.
Assigning a permission set in Setup
- Open Setup and search for Permission Sets.
- Open the set you want, for example the Agentforce admin set.
- Click Manage Assignments, then Add Assignments.
- Tick your own user, click Next, then Assign, then Done.
Reload the browser tab afterward. Setup menus and the builder often do not show new access until the page is reloaded, and sometimes not until you log out and back in.
You can check the result from the user record. Go to Setup > Users, open your user, and look at Permission Set Assignments. The set must be listed there.
Assigning with the CLI (optional)
If you prefer the command line, the Salesforce CLI assigns a set by API name. The API name can differ from the label, so confirm it in Setup first, on the permission set's detail page.
sf org assign permset --name Prompt_Template_Manager --target-org agentforce-devUse --on-behalf-of followed by a username to assign to another user. A second run for a set that is already assigned typically reports an error and not a no-op, so do not script it blindly.
The agent user
A service agent runs as a specific user, which you choose when you create the agent in the builder. Salesforce can create a default agent user for you, or you can pick an existing one. Either way, treat it like a real integration user:
- Give it only the access the agent needs (least privilege).
- Do not reuse your own admin user. The agent would then carry your full access, and its behavior in testing would not match what a limited user sees.
- Keep it active. If the agent user is frozen or deactivated, the agent stops working with an error that does not name the cause.
Because the agent acts as this user, a record the user cannot see does not exist as far as the agent is concerned. The agent will not report a permissions error. It will answer as if the data were empty.
Giving the agent access to your Apex action
The custom action from the Apex chapter is GetOpenCaseCountAction. It uses with sharing, so it respects the running user's record access. It also reads Case and Account data. For the agent user to run it, three things must all be true:
- The user has Apex Class Access to
GetOpenCaseCountAction. - The user has Read on the Case object and on the Account object.
- Sharing rules or org-wide defaults let the user see the relevant cases.
A small permission set grants the first two. Store it in your project as source so it is repeatable:
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Case Count Action Access</label>
<description>Lets a user or agent user run GetOpenCaseCountAction.</description>
<hasActivationRequired>false</hasActivationRequired>
<classAccesses>
<apexClass>GetOpenCaseCountAction</apexClass>
<enabled>true</enabled>
</classAccesses>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Case</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Account</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
</PermissionSet>Save it as force-app/main/default/permissionsets/Case_Count_Action_Access.permissionset-meta.xml. Deploy the class and the permission set together, then assign the set:
sf project deploy start --source-dir force-app --target-org agentforce-dev
sf org assign permset --name Case_Count_Action_Access --target-org agentforce-devThe second command assigns the set to the CLI's logged-in user. To assign it to the agent user, add --on-behalf-of with that user's username, or use Manage Assignments in Setup.
Verifying access
Check in this order, from cheapest to most expensive:
- User detail page. Confirm the permission sets appear under Permission Set Assignments.
- Permission set overview. In the set, open Apex Class Access and Object Settings and confirm your class and objects appear.
- Login As. From Setup > Users, use Login on the agent user if your org allows it, and open a Case list. If you cannot see cases, the agent cannot either.
- Builder preview. Run the action in the conversation preview. The testing chapter covers this in depth.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The Agentforce entry is missing from Setup or the app launcher | Admin permission set not assigned, or page not reloaded | Assign the set, then reload |
| The Apex action is missing from the list of actions you can add | Class is not deployed, or the method lacks `@InvocableMethod` | Redeploy and check the annotation |
| Action runs but returns 0 open cases for accounts that have cases | Agent user lacks Case read or sharing access | Add object access and review sharing |
| "Insufficient access" or a class-not-found error at run time | No Apex Class Access for the agent user | Add the class to a permission set and assign it |
| Assignment fails with a license message | Missing permission set license | Check Permission Set Licenses |
| Preview works for you but not through a channel | You tested as admin, but the agent runs as a limited user | Test with the agent user's access |
Exercise
The conversation preview answers "Account X has 0 open cases", but you can see five open cases for that account in a Case list as an admin. The Apex action itself is correct. Name two permission-related causes and how you would tell them apart.
Show answer
The agent user may lack Read on Case (object access), or it may have object access but not record access to those cases because of org-wide defaults or sharing rules, since the class uses with sharing. To tell them apart, open the agent user's permission sets and check the Case object settings first. If Read is there, use Login As the agent user, or check the sharing settings, and see whether the user can open one of those five cases. If the user cannot open them, sharing is the cause. The agent returns 0 and not an error because the query simply finds no visible rows.
Exercise
Why is assigning "Modify All Data" to the agent user a poor fix for a missing-access problem, and what should you do instead?
Show answer
It bypasses object, field, and record-level protection, so the agent can read and repeat any data to any chat participant. Instead, grant the narrowest access the action needs: Apex Class Access for the class, Read on the specific objects, and sharing access to the relevant records, all in a dedicated permission set assigned to the agent user.