0

I have to create users in scratch org through sfdx cli command and assign profile, role to the user.

The command used is

sfdx force:user:create -u <targetusername> -v <targetdevhubusername> Username=testuser1@my.org LastName=testuser1 Email=me@my.org profileName='System Administrator' generatepassword=true

But I want to assign role as well to the user. Tried few ways like Adding parameter to the user create command

UserRole='System Admin'

But its not working.

Can anybody please help me in assigning role to user through sfdx cli.

And once the user is created through Salesforce UI, we have button to Reset Password or checkbox to Generate new password and notify user immediately.

I want to do the same with sfdx cli.

Can anybody help me here. I am stuck since long time.

Thanks in Advance!

Apurva
  • 63
  • 1
  • 6
  • What does "It's not working" mean? Do you receive an error message? Is there actually a Role named "System Admin" in your org? – David Reed Jun 29 '22 at 05:49
  • Yes I have a role named System Admin. There is no parameter I could foind in sfdx command to assign role to user. – Apurva Jun 29 '22 at 06:17
  • Wow od you consider abandoning that command, writing user creation as Apex snippet and then sfdx force:apex:execute? – eyescream Jun 29 '22 at 06:40
  • How can that be done. I tried executing user.UserRoleId=[select Id from UserRole where Name = 'System Admin'].Id; and run sfdx force:apex:execute, but it gave me error as Error: A value cannot be stored to UserRoleId in type User I am very new to salesforce so facing difficulty here – Apurva Jun 29 '22 at 06:57

0 Answers0