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.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
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;