Search in sources :

Example 1 with SetPasswordResult

use of com.salesforce.soap.partner.SetPasswordResult in project tdi-studio-se by Talend.

the class PartnerSamples method setPasswordSample.

private void setPasswordSample() {
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        QueryResult qr = binding.query("select UserName, LastName, FirstName, Id from User");
        if (qr.getSize() > 0) {
            SObject[] users = qr.getRecords();
            if (users != null) {
                System.out.println("\nUser List: ");
                for (int i = 0; i < users.length; i++) {
                    int printInd = i + 1;
                    SObject user = users[i];
                    System.out.println(printInd + ". " + user.get_any()[0].getValue() + " - " + user.get_any()[2].getValue() + " " + user.get_any()[1].getValue());
                }
            }
            String idToReset = getUserInput("\nEnter user to set password for: ");
            if (idToReset != null) {
                int userIndex = new Integer(idToReset).intValue() - 1;
                String newPassword = getUserInput("Enter the new password: ");
                if (newPassword != null) {
                    String verify = getUserInput("Please verify that you want to reset the password for \n" + users[userIndex].get_any()[2] + " " + users[userIndex].get_any()[1] + "\n to " + newPassword + " by entering OK.");
                    if (verify.equals("OK")) {
                        SetPasswordResult setPasswordResult = binding.setPassword(users[userIndex].getId(), newPassword);
                        if (setPasswordResult != null) {
                            System.out.println("\nThe password for user " + users[userIndex].get_any()[2].getValue() + " " + users[userIndex].get_any()[1].getValue() + " has been reset to " + newPassword);
                            getUserInput("\nHit enter to continue...");
                            return;
                        }
                    }
                }
            }
        }
    } catch (ApiFault af) {
        System.out.println("\nFailed to succesfully set password, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (RemoteException ex) {
        System.out.println("\nFailed to succesfully set password, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
    getUserInput("No password was set....\nHit return to continue...");
}
Also used : QueryResult(com.salesforce.soap.partner.QueryResult) ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject) SetPasswordResult(com.salesforce.soap.partner.SetPasswordResult) RemoteException(java.rmi.RemoteException)

Aggregations

QueryResult (com.salesforce.soap.partner.QueryResult)1 SetPasswordResult (com.salesforce.soap.partner.SetPasswordResult)1 ApiFault (com.salesforce.soap.partner.fault.ApiFault)1 SObject (com.salesforce.soap.partner.sobject.SObject)1 RemoteException (java.rmi.RemoteException)1