1.4 KiB
Role assignment
Detail for the role step. Source of truth: reference org-setup.mjs
assignRoleToCurrentUser (743-822).
Run this step only when a role is configured
(role: { assignee: "currentUser", roleName: "<UserRole name>" } in
org-setup.config.json). If absent, no-op cleanly. assignee is always
currentUser — it is the only value the flow honors. Assigning a role to the
current user is what makes Experience Cloud self-registration work correctly, so
this step normally runs before/with self-reg.
Validate roleName against the SOQL-name whitelist before querying.
Sequence
-
Resolve the role Id:
SELECT Id FROM UserRole WHERE Name = '<roleName>'Zero rows → hard error (
role "<roleName>" not found in org). -
Resolve the current user:
sf org display --target-org <org> --json→result.username. If absent → hard error. -
Idempotency check:
SELECT Id, UserRoleId FROM User WHERE Username = '<username>'If
UserRoleIdis already set, skip — do not override an existing role assignment (lines 796-805). -
Assign:
sf data update record --sobject User \ --where "Username='<username>'" \ --values "UserRoleId='<roleId>'" \ --target-org <org> --jsonNon-zero exit → hard error (
failed to assign role "<roleName>" to <username>).