You need to sign in to do that
Don't have an account?
Bryant Daniels 53
Update Role on User with Apex
Hello I am trying to update a Role on a user by using Apex currently doing this but receiving attempt to dereference null
UserRole ur = [SELECT Id FROM UserRole Where name = 'CEO'];
Profile p = [Select id from Profile where name = 'System Administrator'];
User u = [Select userrole.id from User Where profileID =: p.id];
system.debug('ur' + ur);
system.debug('p' + p);
system.debug('u' + u);
u.userrole.id = ur.id;
UserRole ur = [SELECT Id FROM UserRole Where name = 'CEO'];
Profile p = [Select id from Profile where name = 'System Administrator'];
User u = [Select userrole.id from User Where profileID =: p.id];
system.debug('ur' + ur);
system.debug('p' + p);
system.debug('u' + u);
u.userrole.id = ur.id;
use below updated code its work with out any issue, Hope this will help you.
mark Best ANSWER if its works for you.
Thanks
karthik
All Answers
UserRole ur = [SELECT Id FROM UserRole Where name = 'CEO'];
Profile p = [Select id from Profile where name = 'System Administrator'];
User u = [Select userrole.id from User Where profileID =: p.id];
system.debug('ur' + ur);
system.debug('p' + p);
system.debug('u' + u);
u.userrole.id = ur.id;
update u;
use below updated code its work with out any issue, Hope this will help you.
mark Best ANSWER if its works for you.
Thanks
karthik