3
votes

I am using SOAP Partner API and I have a Developer edition. I am creating users by using API. And upon creation of users I want to email these users temporary password which they can use to login to SalesForce.

This is my code:

SaveResult[] results = connection.create(new SObject[] { user });

if (results[0].isSuccess())
{
out.println("Created user: " + results[0].getId());

//connection.setPassword(results[0].getId(), "password");
ResetPasswordResult rpr = connection.resetPassword(results[0].getId());
String result = rpr.getPassword();
  System.out.println("The temporary password for user ID " + results[0].getId()
        + " is " + result);
}
else
{
out.println("Error: " + results[0].getErrors()[0].getStatusCode() + 
                   ":" + results[0].getErrors()[0].getMessage());
}

This is the output I am getting in console:

The temporary password for user ID 005E0000000MwkZIAS is ucQD2PADs

However, the user is NOT receiving any password. :-(

Thanks,

Wap Rau

2

2 Answers

3
votes

If you build & pass an EmailHeader in your soap request you can control what types of emails will get sent from your request.

It looks like you're using WSC, so you can add this call before calling resetPassword, which will enabled emails being sent to users. This should then send the standard reset password email.

connection.setEmailHeader(false, false, true);
-1
votes

use this class to send out an email. include the pwd variable in the string you want to send the user. there's an example that spells everything out

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm