Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a method that creates a new user and sets a custom password, everything works fine to the point where I try to log in with the new user and get an error that the login details are incorrect. Even the login history for that user does not show any entry stating that the password was incorrect, etc.

I have verified that the username and password both are correct, and it works when I do a subsequent setPassword() using the console.

Example:

User newUser = New User();
//...set user fields
insert newUser;    

String password = getPassword(8);
system.setPassword(newUser.Id, password);
//...email user the password

When I run this in the console the same problem occurs:

User u = new User();

u.username = 'test@test.com';
u.email = 'test@test.com';
u.lastName = 'test';
u.firstName = 'test';
u.alias = 'test1236';
u.languagelocalekey = 'en_US';
u.localesidkey = UserInfo.getLocale();
u.emailEncodingKey = 'UTF-8';
u.timeZoneSidKey = 'America/Los_Angeles';
u.profileId = '00eG0000000FgyJ';
insert u;

system.setPassword(u.id, 'testpassword1');

*UPDATE

I can login after 5 minutes or so after the user is created, I have tried on two different orgs.

share|improve this question
Does the debug log show any errors? – jordan.baucke Jan 9 at 17:36
2  
I recreated and did not have this problem. Is this code inside a try block that might be hiding an error? – zjeh Jan 9 at 17:40
1  
Are you trying to login to test.salesforce.com or login.salesforce.com. If you are in a sandbox you need test.salesforce.com. – Peter Knolle Jan 9 at 17:42
Nope, no errors and this is in a dev org. The user is created and active this is what I have used in the console: User u = new User(); u.username = 'testt99@test.com'; u.email = 'testt99@test.com'; u.lastName = 'test'; u.firstName = 'test'; u.alias = 'test1236'; u.languagelocalekey = 'en_US'; u.localesidkey = UserInfo.getLocale(); u.emailEncodingKey = 'UTF-8'; u.timeZoneSidKey = 'America/Los_Angeles'; u.profileId = '00eG0000000FgyJ'; insert u; system.setPassword(u.id, 'testtest1'); – Rich Jan 9 at 20:20
1  
And I think it goes without saying that you should deactivate that user since you posted real credentials. :-) – Daniel Hoechst Jan 9 at 20:26
show 8 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.