Search in sources :

Example 11 with ApiFault

use of com.salesforce.soap.partner.fault.ApiFault 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 12 with ApiFault

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

the class PartnerSamples method describeTabsSample.

private void describeTabsSample() {
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        DescribeTabSetResult[] dtsrs = binding.describeTabs();
        System.out.println("There are " + new Integer(dtsrs.length).toString() + " tabsets defined.");
        for (int i = 0; i < dtsrs.length; i++) {
            System.out.println("Tabset " + new Integer(i + 1).toString() + ":");
            DescribeTabSetResult dtsr = dtsrs[i];
            String tabSetLabel = dtsr.getLabel();
            String logoUrl = dtsr.getLogoUrl();
            boolean isSelected = dtsr.isSelected();
            DescribeTab[] tabs = dtsr.getTabs();
            System.out.println("Label is " + tabSetLabel + " logo url is " + logoUrl + ", there are " + new Integer(tabs.length) + " tabs defined in this set.");
            for (int j = 0; j < tabs.length; j++) {
                DescribeTab tab = tabs[j];
                String tabLabel = tab.getLabel();
                String objectName = tab.getSobjectName();
                String tabUrl = tab.getUrl();
                System.out.println("\tTab " + new Integer(j + 1) + ": \n\t\tLabel = " + tabLabel + "\n\t\tObject details on tab: " + objectName + "\n\t\t" + "Url to tab: " + tabUrl);
            }
        }
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("Failed to successfully describe tabs.\n\n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("Failed to successfully describe tabs.\n\n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : DescribeTabSetResult(com.salesforce.soap.partner.DescribeTabSetResult) ApiFault(com.salesforce.soap.partner.fault.ApiFault) DescribeTab(com.salesforce.soap.partner.DescribeTab) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 13 with ApiFault

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

the class PartnerSamples method describeSoftphoneLayoutSample.

private void describeSoftphoneLayoutSample() {
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        DescribeSoftphoneLayoutResult slr = binding.describeSoftphoneLayout();
        DescribeSoftphoneLayoutCallType[] callTypes = slr.getCallTypes();
        System.out.println("There are " + callTypes.length + " call types.");
        for (int i = 0; i < callTypes.length; i++) {
            DescribeSoftphoneLayoutCallType callType = callTypes[i];
            DescribeSoftphoneLayoutInfoField[] fields = callType.getInfoFields();
            System.out.println("    There are " + fields.length + " info fields.");
            for (int j = 0; j < fields.length; j++) {
                System.out.println("\t" + fields[j].getName() + "\n");
            }
            DescribeSoftphoneLayoutSection[] sections = callType.getSections();
            System.out.println("\tThere are " + sections.length + " sections on this layout.");
            for (int j = 0; j < sections.length; j++) {
                DescribeSoftphoneLayoutSection section = sections[j];
                DescribeSoftphoneLayoutItem[] items = section.getItems();
                for (int k = 0; k < items.length; k++) {
                    DescribeSoftphoneLayoutItem item = items[k];
                    System.out.println("Section " + j + " - item api name: " + item.getItemApiName());
                }
            }
        }
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to describe softphone layout, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to describe softphone layout , error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) DescribeSoftphoneLayoutItem(com.salesforce.soap.partner.DescribeSoftphoneLayoutItem) DescribeSoftphoneLayoutResult(com.salesforce.soap.partner.DescribeSoftphoneLayoutResult) DescribeSoftphoneLayoutCallType(com.salesforce.soap.partner.DescribeSoftphoneLayoutCallType) DescribeSoftphoneLayoutSection(com.salesforce.soap.partner.DescribeSoftphoneLayoutSection) DescribeSoftphoneLayoutInfoField(com.salesforce.soap.partner.DescribeSoftphoneLayoutInfoField) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 14 with ApiFault

use of com.salesforce.soap.partner.fault.ApiFault 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 15 with ApiFault

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

Aggregations

ApiFault (com.salesforce.soap.partner.fault.ApiFault)25 RemoteException (java.rmi.RemoteException)25 ServiceException (javax.xml.rpc.ServiceException)20 IOException (java.io.IOException)19 SObject (com.salesforce.soap.partner.sobject.SObject)14 MessageElement (org.apache.axis.message.MessageElement)8 QueryResult (com.salesforce.soap.partner.QueryResult)6 SaveResult (com.salesforce.soap.partner.SaveResult)6 DescribeSObjectResult (com.salesforce.soap.partner.DescribeSObjectResult)3 DescribeSoftphoneLayoutInfoField (com.salesforce.soap.partner.DescribeSoftphoneLayoutInfoField)3 GregorianCalendar (java.util.GregorianCalendar)3 HashMap (java.util.HashMap)3 Field (com.salesforce.soap.partner.Field)2 FieldType (com.salesforce.soap.partner.FieldType)2 PicklistEntry (com.salesforce.soap.partner.PicklistEntry)2 SforceServiceLocator (com.salesforce.soap.partner.SforceServiceLocator)2 ArrayList (java.util.ArrayList)2 DeleteResult (com.salesforce.soap.partner.DeleteResult)1 DescribeLayout (com.salesforce.soap.partner.DescribeLayout)1 DescribeLayoutItem (com.salesforce.soap.partner.DescribeLayoutItem)1