1

I'm trying to assign a role to a user using Apex. Here my code:

user.UserRole=[select UserRoleId from UserRole where Name='CEO'].UserRoleId;

But the debugger give the error:

illegal assignment fro Id to UserRole.

4

You're trying to assign UserRole to UserRoleId - trying to assign sObject to Id.

Correct code would be:

user.UserRoleId=[select UserRoleId from UserRole where Name='CEO'].UserRoleId;

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.