+ Start a Discussion
ForceComForceCom 

System.resetpassword() not working correctly ?

HI , 

 

I have the below code , which is a part of the code that i am working on. I am able to retrieve the user  record , user Id and also contact Id . When I try to use the system.resetpassword(), it gives me an unknown exception with error Id, it is wierd  as it seems , since the system.resetpassword() tends to work correctly when i test this method in developer console , it does reset the password. Any help would be greatly appreciated.

 

Map<Id,User> usermap= new Map<Id,User>([Select Id,ContactId from User where ContactId IN: contactIdset]);

system.debug('reset password entered');
if(usermap.size()>0){

for(User user1:usermap.Values()){
system.debug('user id'+user1.Id);
system.debug('contact Id '+user1.ContactId);
system.resetPassword(user1.Id,true);

}
}

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
ForceComForceCom

David, 

 

I had a conversation with Salesforce on this. 

 

System.resetpassword() is not supported in triggers and they are working on resolving it. The work around solution to this would creating a future class and creating a system.resetpassword() in the class, then call the class in the trigger. 

 

Thanks,

Dharani

 

All Answers

David Lee(China Developer)David Lee(China Developer)

I think you need to check 2 items.

1) Does the current running user has the "change/reset password" permissions.

2) In this line:Map<Id,User> usermap= new Map<Id,User>([Select Id,ContactId from User where ContactId IN: contactIdset]);

    Please make sure the currently running user has the permissions to reset the paswword of all portal users.

 

I highly suggest you to add a "try catch block" to catch the exception.

 

ForceComForceCom

David, 

 

I had a conversation with Salesforce on this. 

 

System.resetpassword() is not supported in triggers and they are working on resolving it. The work around solution to this would creating a future class and creating a system.resetpassword() in the class, then call the class in the trigger. 

 

Thanks,

Dharani

 

This was selected as the best answer