Search in sources :

Example 21 with ApiFault

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

the class PartnerSamples method searchSample.

private void searchSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    SearchResult sr = null;
    QueryResult qr = null;
    try {
        sr = binding.search("find {4159017000} in phone fields returning contact(id, phone, firstname, lastname), lead(id, phone, firstname, lastname), account(id, phone, name)");
        SearchRecord[] records = sr.getSearchRecords();
        Vector contacts = new Vector();
        Vector leads = new Vector();
        Vector accounts = new Vector();
        if (records != null && records.length > 0) {
            for (int i = 0; i < records.length; i++) {
                SObject record = records[i].getRecord();
                if (record.getType().toLowerCase().equals("contact")) {
                    contacts.add(record);
                } else if (record.getType().toLowerCase().equals("lead")) {
                    leads.add(record);
                } else if (record.getType().toLowerCase().equals("account")) {
                    accounts.add(record);
                }
            }
            if (contacts.size() > 0) {
                System.out.println("Found " + new Integer(contacts.size()).toString() + " contacts:");
                for (int i = 0; i < contacts.size(); i++) {
                    SObject c = (SObject) contacts.get(i);
                    System.out.println(c.getId() + " - " + c.get_any()[1] + " " + c.get_any()[2] + " - " + c.get_any()[0]);
                }
            }
            if (leads.size() > 0) {
                System.out.println("Found " + new Integer(leads.size()).toString() + " leads:");
                for (int i = 0; i < leads.size(); i++) {
                    SObject l = (SObject) leads.get(i);
                    System.out.println(l.getId() + " - " + l.get_any()[1] + " " + l.get_any()[2] + " - " + l.get_any()[0]);
                }
            }
            if (accounts.size() > 0) {
                System.out.println("Found " + new Integer(accounts.size()).toString() + " accounts:");
                for (int i = 0; i < accounts.size(); i++) {
                    SObject a = (SObject) accounts.get(i);
                    System.out.println(a.getId() + " - " + a.get_any()[1] + " - " + a.get_any()[0]);
                }
            }
        } else {
            System.out.println("No records were found for the search.");
        }
        System.out.println("\nSearch succesfully executed.");
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to execute search succesfully, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to execute search succesfully, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : SearchRecord(com.salesforce.soap.partner.SearchRecord) QueryResult(com.salesforce.soap.partner.QueryResult) ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject) SearchResult(com.salesforce.soap.partner.SearchResult) Vector(java.util.Vector) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 22 with ApiFault

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

the class PartnerSamples method getServerTimestampSample.

private void getServerTimestampSample() {
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    System.out.println("\nGetting server's timestamp...");
    try {
        Calendar cal = binding.getServerTimestamp().getTimestamp();
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
        df.setCalendar(cal);
        System.out.println("Time stamp on server: " + df.format(cal.getTime()));
    } catch (ApiFault af) {
        System.out.println("ERROR: getting server timestamp.\n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (RemoteException ex2) {
        System.out.println("ERROR: getting server timestamp.\n" + ex2.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) DateFormat(java.text.DateFormat) RemoteException(java.rmi.RemoteException)

Example 23 with ApiFault

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

the class PartnerSamples method getDeletedSample.

private void getDeletedSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        // Calendar deletedDate
        GregorianCalendar cal = (GregorianCalendar) binding.getServerTimestamp().getTimestamp();
        GregorianCalendar calEnd = (GregorianCalendar) cal.clone();
        cal.add(GregorianCalendar.MINUTE, -5);
        GetDeletedResult mr = binding.getDeleted("Contact", cal, calEnd);
        if (mr.getDeletedRecords() != null) {
            for (int i = 0; i < mr.getDeletedRecords().length; i++) {
                System.out.println(mr.getDeletedRecords(i).getId() + " was deleted on " + mr.getDeletedRecords(i).getDeletedDate().getTime().toString());
            }
        } else {
            System.out.println("No deletions from contacts in the last 5 minutes.");
        }
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to get deleted records, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to get deleted records, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) GregorianCalendar(java.util.GregorianCalendar) GetDeletedResult(com.salesforce.soap.partner.GetDeletedResult) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 24 with ApiFault

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

the class PartnerSamples method getUpdatedSample.

private void getUpdatedSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        // Calendar deletedDate
        GregorianCalendar cal = (GregorianCalendar) binding.getServerTimestamp().getTimestamp();
        GregorianCalendar calEnd = (GregorianCalendar) cal.clone();
        cal.add(GregorianCalendar.MINUTE, -5);
        GetUpdatedResult mr = binding.getUpdated("Account", cal, calEnd);
        if (mr.getIds() != null && mr.getIds().length > 0) {
            for (int i = 0; i < mr.getIds().length; i++) {
                System.out.println(mr.getIds(i) + " was updated.");
            }
        } else {
            System.out.println("No updates to accounts in the last 5 minutes.");
        }
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to get updated records, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to get updated records, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : GetUpdatedResult(com.salesforce.soap.partner.GetUpdatedResult) ApiFault(com.salesforce.soap.partner.fault.ApiFault) GregorianCalendar(java.util.GregorianCalendar) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 25 with ApiFault

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

the class PartnerSamples method processSample.

private void processSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        // First step is to create an account that matches the approval process criteria
        SObject acct = new SObject();
        acct.setType("Account");
        acct.set_any(new MessageElement[] { newMessageElement("Name", "API Approval Sample") });
        acct.setId(binding.create(new SObject[] { acct })[0].getId());
        // Next step is to submit the account for approval using a ProcessSubmitRequest
        ProcessSubmitRequest psr = new ProcessSubmitRequest();
        psr.setObjectId(acct.getId());
        psr.setComments("This approval request was initiated from the API.");
        ProcessResult p_res = binding.process(new ProcessRequest[] { psr })[0];
        if (p_res.isSuccess()) {
            // Since the submission was successful we can now approve or reject it with
            // a ProcessWorkItmeRequest
            ProcessWorkitemRequest pwr = new ProcessWorkitemRequest();
            pwr.setAction("Approve");
            pwr.setComments("This request was approved from the API.");
            pwr.setWorkitemId(p_res.getNewWorkitemIds(0));
            p_res = binding.process(new ProcessRequest[] { pwr })[0];
            if (p_res.isSuccess()) {
                System.out.println("Successfully submitted and then approved an approval request.");
            } else {
                System.out.println("Error approving the work item: " + p_res.getErrors(0).getMessage());
            }
        } else {
            System.out.println("Error submitting the account for approval: " + p_res.getErrors(0).getMessage());
        }
    } catch (ApiFault e) {
        System.out.println("The API returned a fault: " + e.getExceptionMessage());
    } catch (RemoteException e) {
        System.out.println("There was an Axis generated error: " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
    getUserInput("\nHit the enter key to continue...");
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) ProcessRequest(com.salesforce.soap.partner.ProcessRequest) ProcessWorkitemRequest(com.salesforce.soap.partner.ProcessWorkitemRequest) SObject(com.salesforce.soap.partner.sobject.SObject) ProcessResult(com.salesforce.soap.partner.ProcessResult) ProcessSubmitRequest(com.salesforce.soap.partner.ProcessSubmitRequest) RemoteException(java.rmi.RemoteException) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

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