Here is the code I use to generate a new password for a self-service user. You will not be able to use the code as is but it should give you what you need to accomplish the task.
private function resetPassword($username) { $sfconn = new Sforce_Connection(); try { $qry = "Select Id, ContactId from SelfServiceUser Where Username = '$username'"; $response = $sfconn->query($qry); } catch (Exception $e) { return "We are unable to locate that user name."; } if (count($response) > 0) { // there can be more than one, but only one should have a ContactId $ssid = null; foreach($response as $rec) { if ( !is_null($rec->ContactId)) { $ssid = $rec->Id; break; } } if (! is_null($ssid)) { $ssuser = $sfconn->retrieve($ssid,'SelfServiceUser'); $success = $ssuser->resetPassword(); if ($success) { $result = "You’re password has been reset. You should receive your new password shortly via email."; Zend_Log::log(date('c').": PORTAL: Password reset for $username", Zend_Log::LEVEL_INFO ); } else { $result = "We were not able to reset you’re password Please contact Centive support for urther assistance."; Zend_Log::log(date('c').": PORTAL: Password reset failed for $username", Zend_Log::LEVEL_WARNING ); } } else { Zend_Log::log(date('c').": PORTAL: Could not find Contact for SS user $username", Zend_Log::LEVEL_ERROR ); $result = "There was a problem retrieving your user information. Please contact Centive support."; } } else { $result = "We are unable to locate that user name."; } return $result; }
Does anyone know the syntax that I can use to set the password from Eclipse Anonymously Execute Code section? I periodically need to set batches of self service portal passwords and it would be great if I could do it form Eclipse rather than using C#.
private function resetPassword($username) {
$sfconn = new Sforce_Connection();
try {
$qry = "Select Id, ContactId from SelfServiceUser Where Username = '$username'";
$response = $sfconn->query($qry);
} catch (Exception $e) {
return "We are unable to locate that user name.";
}
if (count($response) > 0) { // there can be more than one, but only one should have a ContactId
$ssid = null;
foreach($response as $rec) {
if ( !is_null($rec->ContactId)) {
$ssid = $rec->Id;
break;
}
}
if (! is_null($ssid)) {
$ssuser = $sfconn->retrieve($ssid,'SelfServiceUser');
$success = $ssuser->resetPassword();
if ($success) {
$result = "You’re password has been reset. You should receive your new password shortly via email.";
Zend_Log::log(date('c').": PORTAL: Password reset for $username", Zend_Log::LEVEL_INFO );
} else {
$result = "We were not able to reset you’re password Please contact Centive support for urther assistance.";
Zend_Log::log(date('c').": PORTAL: Password reset failed for $username", Zend_Log::LEVEL_WARNING );
}
} else {
Zend_Log::log(date('c').": PORTAL: Could not find Contact for SS user $username", Zend_Log::LEVEL_ERROR );
$result = "There was a problem retrieving your user information. Please contact Centive support.";
}
} else {
$result = "We are unable to locate that user name.";
}
return $result;
}
Park
do a query for the self service user id, then use setPassword('userID' => ssuID, 'password' => password)
this will set the password without notifying the ss user.
Does anyone know the syntax that I can use to set the password from Eclipse Anonymously Execute Code section? I periodically need to set batches of self service portal passwords and it would be great if I could do it form Eclipse rather than using C#.
Thanks in advance,
James