Sub topic 6
Roles: what they are and how they differ from profiles
This chapter assumes you can navigate Setup, know what a profile and a permission set are, and can read basic SOQL. It also assumes you have met org-wide defaults (OWD) as the baseline for record access. Roles are the first of the two mechanisms that open access above that baseline. The role hierarchy is the second, and it is the next chapter's subject.
What a role is
A role is a named position in a tree that Salesforce uses to decide record visibility. Each user can be assigned to at most one role. A role belongs to one place in the hierarchy and has one parent role, set by the field "This role reports to". The role at the top has no parent.
Roles do one main job in the sharing model. When a record is owned by a user in a given role, users in roles above that one can get access to it. This chapter covers what a role is and how it is set up. The upward flow of access is covered in the next chapter.
Roles also appear in a few other places:
- Forecasts roll up along the role hierarchy.
- Reports can be shared with a role, or with a role and its subordinates.
- Sharing rules and public groups can target "Role" or "Role and Subordinates".
Roles do not give anyone permission to see, create, edit or delete a type of object. They only affect which records of an object a user can reach, once that user already has permission to the object.
Profiles answer a different question
A profile is required. Every user has exactly one. It defines what the user can do: object permissions (Create, Read, Edit, Delete), field-level security, app and tab visibility, Apex class access, system permissions, login hours and IP ranges. Permission sets add more of the same permissions on top of the profile.
A role is optional. A user can have no role at all. Such a user can still log in and work with records they own, records that OWD makes visible, and records shared to them in other ways. They just do not take part in hierarchy-based access.
The two settings answer separate questions:
| Question | Answered by |
|---|---|
| Can this user read Accounts at all? | Profile or permission sets |
| Can this user edit the Rating field? | Profile or permission sets (field-level security) |
| Which Account records can this user see? | OWD, ownership, role hierarchy, sharing rules and other sharing |
| Is a role required? | No, optional |
| Is a profile required? | Yes, exactly one per user |
| How many can a user have? | One role. One profile, plus any number of permission sets. |
Because the two are independent, you can combine them freely. Two users can share a profile and have different roles. Two users can share a role and have different profiles. A sales manager and a sales rep might both use a "Sales User" profile, while the manager sits one level above the rep in the role hierarchy.
A role is not a reporting line
Roles are often described as a copy of the org chart. That is a good starting guess, but it is wrong in two ways.
First, Salesforce does not derive roles from the standard Manager field on the user record. The Manager field is used for things like approval routing and is set separately. You can change a user's Manager without changing their role, and the reverse.
Second, the role hierarchy should follow data visibility needs, not job titles. Consider a company with a regional director, three team leads and twelve reps. If the leads do not need to see each other's records, and the reps' records only need to flow up to their own lead, the tree mirrors the org chart. But if two job titles at the same level never need access to anything below them, you do not need to create a role for that title at all. Every extra level makes access calculation and administration more work.
A sound approach is to start from the question "Who must be able to see the records owned by these users?" and build the roles from the answers.
Creating and assigning roles
You manage roles in Setup. Search for "Roles" in Quick Find. The page shows the tree and lets you add a role under any existing one. For each role you set:
- Label: the name shown in the tree and on the user record.
- This role reports to: the parent role.
- Role Name as displayed on reports: an optional shorter name for reports.
- Access settings for related objects: depending on your OWD, you can choose whether users in this role get access to Contacts, Opportunities and Cases associated with Accounts they can access.
You then assign a role from the user's own record, in the Role field. Changing a user's role changes which hierarchy position their owned records sit in. It also changes which records flow up to the managers above them. Salesforce recalculates sharing after such a change. In orgs with large data volumes, a mass role change or a restructure of a large branch can take a while to finish, so schedule it outside peak hours.
Deleting a role asks you to choose a replacement role for the users and child roles beneath it. Plan the target before you delete.
Inspecting roles with SOQL
The roles of an org are stored in the UserRole object. This query lists them with their parents, so you can rebuild the tree:
SELECT Id, Name, ParentRoleId
FROM UserRole
ORDER BY NameThis query shows each active user with the profile and role they hold. A blank role in the result means that user has none:
SELECT Name, Profile.Name, UserRole.Name
FROM User
WHERE IsActive = true
ORDER BY UserRole.NameRun both queries in the Developer Console or any SOQL tool. A review of the second result often reveals active users with no role, or users whose role does not match their job.
Common mistakes
- Using roles to grant permissions. A role never grants object, field or system permissions. Fix the profile or permission set instead.
- Making a role for every job title. Extra levels with no data-sharing purpose add recalculation work and confuse administrators.
- Expecting same-role users to share records. They do not, unless OWD is Public Read Only or Public Read/Write, or another rule shares the records.
- Leaving users without a role by accident. Their records never reach any manager through the hierarchy. For some users, such as integration accounts, this may be intentional. Check it deliberately.
- Confusing Manager with role. Changing the Manager field does not change record access.
Exercise
Two users, Priya and Marcus, are both assigned the "Sales User" profile. Priya has the role "Sales Rep EMEA". Marcus has no role. Priya's profile gives Read on Account, and OWD for Account is Private. Describe what each user can see on Account, and name what decides it.
Show answer
The profile gives both users Read permission on the Account object, so object access is the same for both. The role makes no difference to that. Record access differs only through ownership and sharing. With OWD Private, each user sees the Accounts they own and any shared to them. Priya's role lets users in roles above hers, such as an EMEA manager, see the Accounts she owns, but it does not give her access to her colleagues' Accounts. Marcus has no role, so his owned Accounts do not flow up to any manager through the hierarchy. The profile controls what they can do. OWD, ownership and role position control which records they reach.
Exercise
A director says, "Our org chart has seven levels, so we need seven levels of roles." Give two reasons to question this, and say how you would decide which roles to create.
Show answer
First, roles are for record visibility, not for mirroring job titles, and the Manager field on the user is a separate setting. Second, each extra level adds administration and sharing recalculation work, and levels that do not need to see the records below them give no benefit. To decide, ask for each group of users who must see the records owned by which other users, and create a role only where the answer creates a distinct level of access.