Take the 2-minute tour ×
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 '13 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 '13 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 '13 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 '13 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 '13 at 20:26
show 8 more comments

1 Answer 1

The authentication mechanism seems to have a replication delay. Changing your user name results in an email being sent to you:

Dear Mr. User,

Your username has changed.

New username: ABC

Old username: XYZ

The new username may take several minutes to become fully functional. We recommend you log in with the following link for the next 24 hours to avoid problems.

https://na1.salesforce.com/?c=...

If you can't click the link, please copy and paste it into your browser.

Thank you, salesforce.com

I suspect that this same issue occurs when creating a new user; the user is only able to log in immediately because of the magic link they are sent in a new user email. When creating the user through other means, they will most likely experience a delay before they are able to log in using the provided user name.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.