Search in sources :

Example 6 with MessageElement

use of org.apache.axis.message.MessageElement 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 7 with MessageElement

use of org.apache.axis.message.MessageElement in project tdi-studio-se by Talend.

the class PartnerSamples method loadQueryResults.

private ArrayList loadQueryResults(QueryResult qr) {
    ArrayList returnVal = new ArrayList();
    if (qr.getSize() > 0) {
        boolean keepLooping = true;
        while (keepLooping) {
            for (int i = 0; i < qr.getRecords().length; i++) {
                MessageElement[] records = qr.getRecords(i).get_any();
                HashMap fields = new HashMap();
                if (qr.getRecords(i).getId() != null)
                    fields.put("id", qr.getRecords(i).getId());
                for (int j = 0; j < records.length; j++) {
                    MessageElement record = records[j];
                    if (!fields.containsKey(record.getName()))
                        fields.put(record.getName().toLowerCase(), record);
                }
                returnVal.add(fields);
            }
            if (qr.isDone())
                keepLooping = false;
            else
                try {
                    qr = binding.queryMore(qr.getQueryLocator());
                } catch (InvalidQueryLocatorFault e) {
                    System.out.println("\nFailed to query, error message was: \n" + e.getExceptionMessage());
                    getUserInput("\nHit return to continue...");
                } catch (ApiFault af) {
                    System.out.println("\nFailed to query, error message was: \n" + af.getExceptionMessage());
                    getUserInput("\nHit return to continue...");
                } catch (RemoteException e) {
                    e.printStackTrace();
                    getUserInput("\nHit return to continue...");
                }
        }
    }
    return returnVal;
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InvalidQueryLocatorFault(com.salesforce.soap.partner.fault.InvalidQueryLocatorFault) MessageElement(org.apache.axis.message.MessageElement) RemoteException(java.rmi.RemoteException)

Example 8 with MessageElement

use of org.apache.axis.message.MessageElement 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 9 with MessageElement

use of org.apache.axis.message.MessageElement 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

MessageElement (org.apache.axis.message.MessageElement)9 ApiFault (com.salesforce.soap.partner.fault.ApiFault)8 RemoteException (java.rmi.RemoteException)8 SObject (com.salesforce.soap.partner.sobject.SObject)7 IOException (java.io.IOException)7 ServiceException (javax.xml.rpc.ServiceException)7 SaveResult (com.salesforce.soap.partner.SaveResult)6 HashMap (java.util.HashMap)2 DeleteResult (com.salesforce.soap.partner.DeleteResult)1 DescribeSObjectResult (com.salesforce.soap.partner.DescribeSObjectResult)1 MergeRequest (com.salesforce.soap.partner.MergeRequest)1 MergeResult (com.salesforce.soap.partner.MergeResult)1 QueryResult (com.salesforce.soap.partner.QueryResult)1 UpsertResult (com.salesforce.soap.partner.UpsertResult)1 InvalidQueryLocatorFault (com.salesforce.soap.partner.fault.InvalidQueryLocatorFault)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Element (org.w3c.dom.Element)1