Role defines a named position in an organization's role hierarchy. Its parent relationship establishes where the role sits in that hierarchy. Roles can be targets in sharing configurations, queues, approvals, workflow, report filters, delegated administration, and analytics sharing. Role settings also control an account owner's access to certain related records owned by other users.
A Role component is not a user assignment or a complete description of a user's permissions. Determining who occupies a role and what those users can access also requires live user assignments and the applicable sharing and permission configuration. The metadata identifier, a runtime UserRole record ID, and a sharing-group ID are different identifiers.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
The unique API identifier, corresponding to Role Name in the user interface. It must begin with a letter and contain only alphanumeric characters and underscores. Spaces, a trailing underscore, and consecutive underscores are not permitted. It is distinct from name. |
name |
The required name of the role. Do not confuse this element with the component's fullName identifier. |
parentRole |
The Role immediately above this role. Following these references establishes the hierarchy. |
caseAccessLevel |
The user's access to other users' cases associated with accounts the user owns. This is not a general Case permission. |
contactAccessLevel |
The user's access to other users' contacts associated with accounts the user owns. This is not a general Contact permission. |
opportunityAccessLevel |
The user's access to other users' opportunities associated with accounts the user owns. This is not a general Opportunity permission. |
mayForecastManagerShare |
A boolean, true or false, indicating whether the forecast manager can manually share their own forecast. It does not grant general record-sharing authority. |
Behavior and Constraints
A hierarchy move can affect components that do not directly reference the moved role. Changing parentRole changes the role's ancestry. Consumers targeting an ancestor role and its subordinates can therefore be affected even when their own configuration remains unchanged.
The three related-record access settings have an account-ownership scope. caseAccessLevel, contactAccessLevel, and opportunityAccessLevel govern access to other users' records associated with accounts the user owns. Reading these settings as permissions over every case, contact, or opportunity would overstate their effect.
mayForecastManagerShare concerns the forecast manager's own forecast. It does not describe general record sharing or permission to share every subordinate's forecast.
Role-targeting selectors are not interchangeable. Sharing and list-view structures distinguish role, roleAndSubordinates, and roleAndSubordinatesInternal. Sharing-rule structures also expose portalRole and portalRoleandSubordinates. Queue structures use the different, singular spellings roleAndSubordinate and roleAndSubordinateInternal.
Deployment and Retrieval
In Metadata API package format, Role components use the .role file suffix and reside in the roles directory of the corresponding package directory. The manifest type name is Role. This type supports the * wildcard in package.xml to request all Role components.
Hierarchy dependencies run in both directions: a role's parentRole points to its parent, and other Role components can point to it as their parent. A deployment that changes a parent relationship can also change the scope of existing role-and-subordinate consumers. Those consumers are potential dependencies, not an automatic list of components that must accompany every Role deployment.
Retrieving Role components alone does not establish which users currently occupy those roles or their effective access. The hierarchy definition must be interpreted alongside live user assignments, sharing, and permissions.
Relationships
The parent-role connection defines the hierarchy; incoming references identify configurations that can consume it. Some entries below are structures within a containing metadata type, such as sharing-rule and workflow structures, rather than separate deployment units. These connections describe possible references, not proof that every category currently uses a particular role.
References
-
Role:parentRole.
Referenced By
-
ApprovalProcess: role-valuednameandsubmitterentries. These are references within the approval configuration, not the approval process's own identity. -
CustomObject:role,roleAndSubordinates,roleAndSubordinatesInternal. -
DelegateGroup:roles. -
ListView:role,roleAndSubordinates,roleAndSubordinatesInternal. -
Queue:role,roleAndSubordinate,roleAndSubordinateInternal. -
Report:roleHierarchyFilter. -
Role:parentRole. -
SharingRules:portalRole,portalRoleandSubordinates,role,roleAndSubordinates,roleAndSubordinatesInternal. -
SharingCriteriaRule:portalRole,portalRoleandSubordinates,role,roleAndSubordinates,roleAndSubordinatesInternal. -
SharingGuestRule:portalRole,portalRoleandSubordinates,role,roleAndSubordinates,roleAndSubordinatesInternal. -
SharingOwnerRule:portalRole,portalRoleandSubordinates,role,roleAndSubordinates,roleAndSubordinatesInternal. -
SharingTerritoryRule:portalRole,portalRoleandSubordinates,role,roleAndSubordinates,roleAndSubordinatesInternal. -
WaveAnalyticAssetCollection:sharedTo. -
WaveApplication:sharedTo. -
Workflow:assignedTo,field,recipient, depending on the structure. -
WorkflowAlert:field,recipient. -
WorkflowTask:assignedTo.
Reported Issues
- Moving a user to a different role is not a substitute for granting field access. In a 2014 custom-field visibility discussion, community guidance distinguished role-based record visibility from object and field permissions managed through profiles and permission sets. For this diagnosis, check field-level security, which controls access to individual fields. Field visibility and roles.
- A high hierarchy position did not provide edit access to an Account owned by a user with no role. In a 2019 report involving a Private or Public Read Only sharing model, the explanation was that the owner was outside the hierarchy, so there was no ancestor relationship through which access could roll up. Manual sharing with write access was proposed as a targeted remedy. Access to records owned by a user without a role.
- Read/write sharing did not necessarily permit ownership transfer. In a 2017 discussion, users shared records across hierarchy levels but users lower in the hierarchy could not transfer records owned by users above them. The guidance distinguished editing from transferring ownership and noted object-specific exceptions, including transfer access available through sharing for some objects. Editing versus transferring ownership.
- An empty external-user role selector can reflect the user license rather than a missing Role component. In a 2017 discussion, community guidance distinguished Customer Community users, which do not use roles, from Customer Community Plus users, which do. Customer Community role assignment.
-
Using a runtime
UserRoleID as a share record'sUserOrGroupIdcaused an incorrect-ID-type error. In a 2024 Apex sharing report, the role-only sharing target was the relatedGrouprecord, linked throughRelatedIdand selected withType = 'Role'. This concerns runtime records, not the Role metadatafullName, and does not establish the selector for a role-and-subordinates group. Role IDs and sharing-group IDs. -
Assigning an existing built-in role produced an internal error in a scratch org. A 2019 report described this particularly for scratch orgs created with
hasSampleData: false. The reported workaround replaced the scratch org's roles with a newly createdUserRolebefore assignment. This was a runtime user-provisioning workaround, not a Role metadata deployment procedure. Scratch-org role assignment error. - Partner peer access was addressed through a user-level feature rather than a separate sharing rule for every partner account. In a 2017 discussion using a Private sharing model and account-specific partner roles, Partner Super User Access was proposed to give a partner user access to records owned by users in the same role and roles below it, but not roles above it. This is distinct from changing the Role component's parent or access-level settings. Partner users and peer record access.
Common Questions
How do I retrieve all Salesforce roles with Metadata API?
Use Role as the type name and * as the member in package.xml. In Metadata API package format, the components are stored in the roles directory with the .role suffix. The retrieval alone does not identify current user assignments or effective access.
What is the difference between Role fullName and name?
fullName is the unique API identifier and corresponds to Role Name in the user interface. It follows the identifier restrictions listed above. name is a separate, required element.
Do Role access-level settings grant access to all cases, contacts, and opportunities?
No. caseAccessLevel, contactAccessLevel, and opportunityAccessLevel apply to other users' related records associated with accounts the user owns. They are not general object permissions.
Why did moving a role affect a sharing rule that I did not change?
Changing parentRole changes ancestry. A rule targeting a role and its subordinates can therefore cover a different hierarchy after the move, even if it does not directly reference the moved role.
Can I use a UserRole ID in UserOrGroupId for Apex sharing?
In the reported failure, the UserRole ID was the wrong ID type. The role-only target was the related Group record, found through RelatedId with Type = 'Role'. Neither runtime ID is the Role metadata fullName.