I have below trigger that needs to activate the User as well as generate reset password link for the same when a custom checkbox field is checked. Below is my apex trigger code that throws this error on an inactive user's detail page as I try to Save the checkbox checked. Basically making Isactive field of User as checked through trigger is not happening. Can someone please help.
Apex Trigger:
trigger TrainingCompleted on User (before update) {
for (User updated : Trigger.new) {
if(updated.Training_Complete_abv__c = true)
{ updated.IsActive =true;
if( updated.IsActive =true)
System.resetPassword(updated.Id,true);// error line
}
}
}
Error:
execution of BeforeUpdate caused by: System.UnexpectedException: INACTIVE_OWNER_OR_USER: owner or user is inactive. Org Id:00D8A0000008i2Q User Id:005F0000003mdWV: Trigger.TrainingCompleted: