Search in sources :

Example 16 with SObject

use of com.salesforce.soap.partner.sobject.SObject 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 17 with SObject

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

the class PartnerSamples method mergeSample.

private void mergeSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        SObject masterAccount = new SObject();
        MessageElement masterAccountName = newMessageElement("Name", "MasterAccount");
        masterAccount.set_any(new MessageElement[] { masterAccountName });
        masterAccount.setType("Account");
        SaveResult masterAccountSaveResult;
        masterAccountSaveResult = binding.create(new SObject[] { masterAccount })[0];
        masterAccount.setId(masterAccountSaveResult.getId());
        MessageElement masterAccountDescription = newMessageElement("Description", "Old description");
        masterAccount.set_any(new MessageElement[] { masterAccountName, masterAccountDescription });
        SObject accountToMerge = new SObject();
        accountToMerge.setType("Account");
        MessageElement mergeAccountName = newMessageElement("Name", "AccountToMerge");
        MessageElement mergeAccountDesc = newMessageElement("Description", "Duplicate account");
        accountToMerge.set_any(new MessageElement[] { mergeAccountDesc, mergeAccountName });
        SaveResult accountToMergeSaveResult = binding.create(new SObject[] { accountToMerge })[0];
        // Attach a note, which will get re-parented
        SObject note = new SObject();
        note.setType("Note");
        MessageElement noteParentId = newMessageElement("ParentId", accountToMergeSaveResult.getId());
        MessageElement noteBody = newMessageElement("Body", "This note will be moved to the MasterAccount during merge.");
        MessageElement noteTitle = newMessageElement("Title", "Test note to be reparented.");
        note.set_any(new MessageElement[] { noteBody, noteParentId, noteTitle });
        @SuppressWarnings("unused") SaveResult noteSave = binding.create(new SObject[] { note })[0];
        MergeRequest mr = new MergeRequest();
        // Perform an update on the master record as part of the merge:
        masterAccountDescription = newMessageElement("Description", "Was merged");
        masterAccount.set_any(new MessageElement[] { masterAccountName, masterAccountDescription });
        mr.setMasterRecord(masterAccount);
        mr.setRecordToMergeIds(new String[] { accountToMergeSaveResult.getId() });
        MergeResult result = binding.merge(new MergeRequest[] { mr })[0];
        getUserInput("Merged " + result.isSuccess() + " got " + result.getUpdatedRelatedIds().length + " updated child records\nHit return to continue.");
    } catch (ApiFault e) {
        System.out.println("Error merging account: " + e.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (RemoteException e) {
        System.out.println("Error from the server on the merge sample: " + e.getMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MergeRequest(com.salesforce.soap.partner.MergeRequest) ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject) MergeResult(com.salesforce.soap.partner.MergeResult) MessageElement(org.apache.axis.message.MessageElement) SaveResult(com.salesforce.soap.partner.SaveResult) RemoteException(java.rmi.RemoteException) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 18 with SObject

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

Example 19 with SObject

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

the class PartnerSamples method createContactSample.

private void createContactSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        SObject[] cons = new SObject[2];
        MessageElement[] contact;
        for (int j = 0; j < cons.length; j++) {
            int index = 0;
            if (accounts != null) {
                contact = new MessageElement[18];
                contact[index++] = newMessageElement("AccountId", accounts[0]);
            } else {
                contact = new MessageElement[17];
            }
            contact[index++] = newMessageElement("AssistantName", "Jane");
            contact[index++] = newMessageElement("AssistantPhone", "777.777.7777");
            contact[index++] = newMessageElement("Department", "Purchasing");
            contact[index++] = newMessageElement("Description", "International IT Purchaser");
            contact[index++] = newMessageElement("Email", "joeblow@isp.com");
            contact[index++] = newMessageElement("Fax", "555.555.5555");
            contact[index++] = newMessageElement("MailingCity", "San Mateo");
            contact[index++] = newMessageElement("MailingCountry", "US");
            contact[index++] = newMessageElement("MailingState", "CA");
            contact[index++] = newMessageElement("MailingStreet", "1129 B Street");
            contact[index++] = newMessageElement("MailingPostalCode", "94105");
            contact[index++] = newMessageElement("MobilePhone", "888.888.8888");
            contact[index++] = newMessageElement("FirstName", "Joe");
            contact[index++] = newMessageElement("LastName", "Blow");
            contact[index++] = newMessageElement("Salutation", "Mr.");
            contact[index++] = newMessageElement("Phone", "999.999.9999");
            contact[index++] = newMessageElement("Title", "Purchasing Director");
            cons[j] = new SObject();
            cons[j].setType("Contact");
            cons[j].set_any(contact);
        }
        SaveResult[] sr = binding.create(cons);
        for (int j = 0; j < sr.length; j++) {
            if (sr[j].isSuccess()) {
                System.out.println("A contact was create with an id of: " + sr[j].getId());
                if (accounts != null) {
                    System.out.println(" - the contact was associated with the account you created with an id of " + accounts[0] + ".");
                }
                if (contacts == null) {
                    contacts = new String[] { sr[j].getId() };
                } else {
                    String[] tempContacts = null;
                    tempContacts = new String[contacts.length + 1];
                    for (int i = 0; i < contacts.length; i++) {
                        tempContacts[i] = contacts[i];
                    }
                    tempContacts[contacts.length] = sr[j].getId();
                    contacts = tempContacts;
                }
            } else {
                // array and write them to the screen
                for (int i = 0; i < sr[j].getErrors().length; i++) {
                    // get the next error
                    com.salesforce.soap.partner.Error err = sr[j].getErrors()[i];
                    System.out.println("Errors were found on item " + new Integer(j).toString());
                    System.out.println("Error code is: " + err.getStatusCode().toString());
                    System.out.println("Error message: " + err.getMessage());
                }
            }
        }
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to create contacts, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to create contacts, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : MessageElement(org.apache.axis.message.MessageElement) SaveResult(com.salesforce.soap.partner.SaveResult) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException) ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject)

Example 20 with SObject

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

the class PartnerSamples method updateAccountSample.

private void updateAccountSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        // check to see if there are any accounts created in this session
        if (accounts == null) {
            System.out.println("\nUpdate operation not completed.  You will need to create an account during this session to run the update sample.");
            getUserInput("\nHit return to continue...");
            return;
        }
        // create the account object to hold our changes
        SObject updateAccount = new SObject();
        updateAccount.setType("Account");
        // need to have the id so that web service knows which account to
        // update
        updateAccount.setId(accounts[0]);
        // set a new value for the name property
        MessageElement[] ufields = new MessageElement[1];
        ufields[0] = newMessageElement("Name", "New Account Name from Update Sample");
        updateAccount.set_any(ufields);
        // create one that will throw an error
        SObject errorAccount = new SObject();
        errorAccount.setType("Account");
        errorAccount.setId(new String("SLFKJLFKJ"));
        errorAccount.setFieldsToNull(new String[] { "Name" });
        // call the update passing an array of object
        SaveResult[] saveResults = binding.update(new SObject[] { updateAccount, errorAccount });
        // loop through the results, checking for errors
        for (int j = 0; j < saveResults.length; j++) {
            System.out.println("Item: " + new Integer(j).toString());
            if (saveResults[j].isSuccess()) {
                System.out.println("An account with an id of: " + saveResults[j].getId() + " was updated.\n");
            } else {
                System.out.println("Item " + new Integer(j).toString() + " had an error updating.");
                System.out.println("    The error reported was: " + saveResults[j].getErrors()[0].getMessage() + "\n");
            }
        }
    } catch (ApiFault af) {
        System.out.println("\nFailed to succesfully update an account, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to succesfully update an account, error message was: \n" + ex.getMessage());
    }
    getUserInput("\nHit return to continue...");
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject) MessageElement(org.apache.axis.message.MessageElement) SaveResult(com.salesforce.soap.partner.SaveResult) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Aggregations

SObject (com.salesforce.soap.partner.sobject.SObject)25 RemoteException (java.rmi.RemoteException)17 IOException (java.io.IOException)15 ServiceException (javax.xml.rpc.ServiceException)15 ApiFault (com.salesforce.soap.partner.fault.ApiFault)14 QueryResult (com.salesforce.soap.partner.QueryResult)10 SaveResult (com.salesforce.soap.partner.SaveResult)9 MessageElement (org.apache.axis.message.MessageElement)7 DescribeSObject (com.salesforce.soap.partner.DescribeSObject)5 UpsertResult (com.salesforce.soap.partner.UpsertResult)3 OMElement (org.apache.axiom.om.OMElement)3 Create (com.salesforce.soap.partner.Create)2 DeleteResult (com.salesforce.soap.partner.DeleteResult)2 ID (com.salesforce.soap.partner.ID)2 Update (com.salesforce.soap.partner.Update)2 Upsert (com.salesforce.soap.partner.Upsert)2 HashMap (java.util.HashMap)2 Delete (com.salesforce.soap.partner.Delete)1 DeleteResponse (com.salesforce.soap.partner.DeleteResponse)1 DescribeSObjectResult (com.salesforce.soap.partner.DescribeSObjectResult)1