0

Throughout execution yaml file for CI/CD process in GitLab I am using sfdx force:data:soql:query -q "SELECT id FROM UserRole where name='CER' " -t -u qwerty@mycompany.org to find proper id for UserRole CER (as result i catch id). I want to assign this value to some variable and after that use it in next sfdx command (replace RoleId) - sfdx force:data:record:update -s User -u qwerty@mycompany.org -w "Name='User User'" -v "UserRoleId=RoleId" .

Please tell me how this can be done? Thank you!

0

I'd just do this with an Anonymous Apex script instead.

update new User(Id = UserInfo.getUserId(), RoleId = [SELECT Id FROM UserRole WHERE Name = 'CER'].Id);

The run it with force:apex:execute.

5
  • Could you explain. – SFguru Oct 7 '20 at 18:03
  • @SFguru What specifically are you asking? – David Reed Oct 7 '20 at 18:07
  • Could you explain. 1) SFDX command - sfdx force:apex:execute -f /user/Role.cls -u qwerty@mycompany.org 2) How use this in Apex class (how it works for you - do we need some special things) - I am trying change/set custom Role for scratch org admin. – SFguru Oct 7 '20 at 18:13
  • There is no Apex class involved. You just need to place code like what I showed above. in a file and run it with the sfdx force:apex:execute command in your pipeline. The command in your comment appears to be correct. – David Reed Oct 7 '20 at 18:17
  • Thank you a lot! Nice solution! – SFguru Oct 7 '20 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.