Skip to content

feat: allow assigning role during user creation via developername#1415

Open
baslu93 wants to merge 1 commit intosalesforcecli:mainfrom
baslu93:main
Open

feat: allow assigning role during user creation via developername#1415
baslu93 wants to merge 1 commit intosalesforcecli:mainfrom
baslu93:main

Conversation

@baslu93
Copy link
Copy Markdown

@baslu93 baslu93 commented Apr 22, 2026

What does this PR do?

This PR enables the assignment of a UserRole when creating users via CLI command, whether through variables or within the definition file. This allows for the configuration of multiple users with different roles, which is particularly useful for testing access rights in automated scenarios or for providing pre-configured users to business stakeholders within a scratch org environment.

Technical Implementation

Since Role IDs are dynamic, I implemented logic that resolves a provided roleDeveloperName into its corresponding Org-specific ID. This lookup logic is conditional; it only triggers if a developer name is explicitly provided, otherwise preserving the existing as-is behavior. I opted to use the DeveloperName instead of the standard Name to ensure uniqueness and to avoid issues with special characters or localization.

During testing, I identified an issue where DevHubs with different default languages failed to the locate the Standard User profile. To resolve this, I updated the project-scratch-def.json file to include language=en_US, ensuring consistent behavior across different DevHub configurations.

Testing and Project Configuration

To validate these changes, I added a unit test that verifies the correct transformation of the role parameter. Furthermore, within the df17AppBuilding project, I defined a custom role to avoid issues related to the default roles and updated the complexUser.json definition to assign the "Guide" role, aligned with the project's volunteering theme.

@salesforce-cla
Copy link
Copy Markdown

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Luca Bassani <l***@l***.i***.s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated.

@baslu93
Copy link
Copy Markdown
Author

baslu93 commented Apr 23, 2026

Updated the commit author from Salesforce email to my personal email

@baslu93 baslu93 changed the title feat: allow assigning developer role during user creation feat: allow assigning role during user creation via developername Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant