Search in sources :

Example 6 with QueryResult

use of com.salesforce.soap.partner.QueryResult 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)

Example 7 with QueryResult

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

the class PartnerSamples method resetPasswordSample.

private void resetPasswordSample() {
    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 reset: ");
            if (idToReset != null) {
                int userIndex = new Integer(idToReset).intValue() - 1;
                String verify = getUserInput("Please verify that you want to reset the password for \n" + users[userIndex].get_any()[2] + " " + users[userIndex].get_any()[1] + "\nby entering OK.");
                if (verify.equals("OK")) {
                    ResetPasswordResult resetPasswordResult = binding.resetPassword(users[userIndex].getId());
                    if (resetPasswordResult != null) {
                        System.out.println("\nThe password for user " + users[userIndex].get_any()[2].getValue() + " " + users[userIndex].get_any()[1].getValue() + " has been reset to " + resetPasswordResult.getPassword());
                        getUserInput("\nHit enter to continue...");
                        return;
                    }
                }
            }
        }
    } catch (ApiFault af) {
        System.out.println("\nFailed to succesfully reset password, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (RemoteException ex) {
        System.out.println("\nFailed to succesfully reset password, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
    getUserInput("No password was reset....\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) ResetPasswordResult(com.salesforce.soap.partner.ResetPasswordResult) RemoteException(java.rmi.RemoteException)

Example 8 with QueryResult

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

the class PartnerSamples method queryAllSample.

private void queryAllSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    // For this sample we will create an account and then delete it
    // to demonstrate the power of queryAll
    String accountName = getUserInput("\nEnter a name for a test account:");
    if (accountName == null || accountName.length() == 0) {
        return;
    }
    createAndDeleteAnAccount(accountName);
    // Now for Query All. Query all allows you to return items that have been moved to the recycle
    // bin, like the account we just deleted.
    QueryResult qr = null;
    try {
        qr = binding.queryAll("select id, Name from Account where name = '" + accountName + "' and IsDeleted = true");
        if (qr.getSize() != 0) {
            SObject account = qr.getRecords()[0];
            System.out.println("Retrieved the deleted account: " + getFieldValue(account.get_any(), "Name"));
        } else {
            System.out.println("Hmm...\nDid not find the account, that's strange.");
        }
        System.out.println("\nQuery succesfully executed.");
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to execute query succesfully, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to execute query succesfully, error message was: \n" + ex.getMessage());
        getUserInput("\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) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 9 with QueryResult

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

the class PartnerSamples method getUnconvertedLead.

private SObject getUnconvertedLead() throws Exception {
    SObject leadToReturn = null;
    // get a list of leads so the user can select one
    QueryResult qr = binding.query("Select Id, FirstName, LastName from Lead where ConvertedDate = Null");
    if (qr.getSize() == 0) {
        // No leads where found that have not been
        // converted, so....
        // we will create a lead and then run the query again
        System.out.println("No unconverted leads found, will create one for you...");
        createLeadSample();
        qr = binding.query("Select Id, FirstName, LastName from Lead where ConvertedDate = Null");
    }
    if (qr.getSize() > 0) {
        for (int i = 0; i < qr.getRecords().length; i++) {
            SObject lead = qr.getRecords()[i];
            System.out.println(new Integer(i + 1).toString() + ": " + getFieldValue(lead.get_any(), "FirstName") + " " + getFieldValue(lead.get_any(), "LastName"));
        }
        String selectedLead = getUserInput("/nSelect the number of the lead to convert. ");
        if (selectedLead != null) {
            try {
                int selLead = new Integer(selectedLead).intValue();
                leadToReturn = qr.getRecords(selLead - 1);
            } catch (Exception ex) {
                System.out.println("The number you selected is not valid, conversion failed...");
            }
        }
    }
    if (leadToReturn == null) {
        throw new Exception("No lead selected, required data, conversion failed");
    } else {
        return leadToReturn;
    }
}
Also used : QueryResult(com.salesforce.soap.partner.QueryResult) SObject(com.salesforce.soap.partner.sobject.SObject) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 10 with QueryResult

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

the class PartnerSamples method getAccount.

private SObject getAccount() throws Exception {
    SObject accountToReturn = null;
    // get a list of Accounts so the user can select one
    QueryResult qr = binding.query("Select Id, Name from Account");
    if (qr.getSize() == 0) {
        // No accounts found (Not Likely), so...
        // we will create an account and then run the query again
        this.createAccountSample();
        qr = binding.query("Select Id, Name from Account");
    }
    if (qr.getSize() > 0) {
        for (int i = 0; i < qr.getRecords().length; i++) {
            SObject account = qr.getRecords(i);
            System.out.println(new Integer(i + 1).toString() + ": " + getFieldValue(account.get_any(), "Name"));
        }
        String selectedAccount = getUserInput("/nSelect the number of the account to use. ");
        if (selectedAccount != null) {
            try {
                int selAccount = new Integer(selectedAccount).intValue();
                accountToReturn = qr.getRecords(selAccount - 1);
            } catch (Exception ex) {
                System.out.println("The number you selected is not valid, exiting...");
            }
        }
    }
    if (accountToReturn == null) {
        throw new Exception("Bad account selection, conversion failed.");
    } else {
        return accountToReturn;
    }
}
Also used : QueryResult(com.salesforce.soap.partner.QueryResult) SObject(com.salesforce.soap.partner.sobject.SObject) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Aggregations

QueryResult (com.salesforce.soap.partner.QueryResult)15 SObject (com.salesforce.soap.partner.sobject.SObject)10 RemoteException (java.rmi.RemoteException)9 IOException (java.io.IOException)7 ServiceException (javax.xml.rpc.ServiceException)7 ApiFault (com.salesforce.soap.partner.fault.ApiFault)6 QueryOptions (com.salesforce.soap.partner.QueryOptions)4 SforceServiceLocator (com.salesforce.soap.partner.SforceServiceLocator)2 HashMap (java.util.HashMap)2 DescribeSObjectResult (com.salesforce.soap.partner.DescribeSObjectResult)1 LoginResult (com.salesforce.soap.partner.LoginResult)1 Query (com.salesforce.soap.partner.Query)1 QueryAll (com.salesforce.soap.partner.QueryAll)1 QueryMore (com.salesforce.soap.partner.QueryMore)1 ResetPasswordResult (com.salesforce.soap.partner.ResetPasswordResult)1 SearchRecord (com.salesforce.soap.partner.SearchRecord)1 SearchResult (com.salesforce.soap.partner.SearchResult)1 SessionHeader (com.salesforce.soap.partner.SessionHeader)1 SetPasswordResult (com.salesforce.soap.partner.SetPasswordResult)1 UpsertResult (com.salesforce.soap.partner.UpsertResult)1