1

I'm try to set a user password and executing the system.setPassword(UserId, Password) method and I always get an error saying that the UserId is invalid. I've checked it and it's the correct UserId. Example: System.setPassword('test@test.com','test');

3

The first parameter of that function call is the actual id of the user object. User Ids start with 005 and are 15 or 18 Characters long. for example:

System.setPassword('005300000123aBc','A$tr0ngPW');
1

I hope you're not hard coding passwords, here's a few lines to generate a random alphanumeric char. Use as you will.

final String selectionString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
Integer idNum = Math.mod(Math.abs(Crypto.getRandomInteger()), selectionString.length());
String randomChar = selectionString.substring(idNum, idNum+1);
  • 1
    I'm only hardcoding the passwords in our training sandbox to make user logins easier during the end user training. Thanks for the code snippet though...that will come in handy. – Ben Dec 8 '16 at 17:49
1

You can't hard code the UserId and password. You can try like this System.setPassword(u.id,passwordString);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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