Sub topic 5
Granting access with permission sets
This chapter assumes you know basic Salesforce administration: users, profiles, permission sets, and the difference between object and field permissions. It also assumes you know what an Agentforce agent, a topic, and an action are. The previous chapters covered the agent user and least privilege. Here you apply them by building the permission set that gives the agent user its access.
Why permission sets and not profiles
An agent that runs as a dedicated agent user can only do what that user can do. Two things define that access: the user's profile and any permission sets assigned to it.
Use a minimal profile for the agent user and grant everything else through permission sets. A permission set adds access and never removes it. That makes the agent's access easy to audit, because you can read the list of assigned permission sets and see exactly what the agent has been given.
Small, task-focused permission sets also work better than one large set. If the agent needs to read orders today and read cases tomorrow, you assign a second set. You do not edit a broad one.
Build a read-only permission set
The example below gives the agent user read access to the Order object and its Status field. It grants no create, edit, delete, view-all, or modify-all rights.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Agent Order Read</label>
<description>Read-only access to orders for the service agent user</description>
<hasActivationRequired>false</hasActivationRequired>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Order</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Order.Status</field>
<readable>true</readable>
</fieldPermissions>
</PermissionSet>Note what the file does and does not contain:
allowReadis the only object permission set totrue.viewAllRecordsandmodifyAllRecordsstayfalse, so the agent is still limited by sharing.- Only
Order.Statusis listed as a field permission. Any other field on Order stays hidden from the agent unless another assigned permission set grants it. hasActivationRequiredisfalse, so the permission set applies as soon as it is assigned. It is not tied to a session.
Assign the permission set
Deploy the file with your normal metadata process, then assign it to the agent user. In Setup, open the agent user, go to Permission Set Assignments, and add Agent Order Read. You can also assign it with Salesforce CLI:
sf org assign permset --name Agent_Order_Read --on-behalf-of [email protected]The API name is derived from the label. If your org uses a different name, use that one.
The agent may also need access to other things that sit outside object permissions. These include the Apex classes behind its actions, which are granted through the permission set's class access, and any flows it runs. A missing class permission is a common reason an action fails for the agent but works when an admin tests it.
How the pieces fit
The permission set decides which objects and fields are available. Sharing then decides which records. The next chapter covers sharing in detail.
Common mistakes
- Cloning the System Administrator profile for the agent user. This grants far more than any topic needs.
- Granting View All or Modify All on an object to avoid sharing problems. This bypasses record-level restrictions.
- Granting a field as editable when the agent only needs to read it.
- Forgetting Apex class access, which causes errors only when the agent runs the action.
Exercise
An admin tests the Get Order Status action and it works. The agent runs the same action and fails with an access error on the Apex class. What is the most likely cause, and how do you fix it?
Show answer
The agent user lacks access to the Apex class, while the admin has it through a different profile or permission set. Add the class to the Apex Class Access section of a permission set, such as Agent Order Read, and assign that set to the agent user.
Exercise
Why does the Agent Order Read permission set leave viewAllRecords set to false?
Show answer
View All Records bypasses sharing for that object. Leaving it false keeps the agent limited to the records the sharing model lets the agent user see, which follows least privilege.