Search in sources :

Example 1 with QueryOptions

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

the class PartnerSamples method querySample.

private void querySample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    QueryResult qr = null;
    QueryOptions qo = new QueryOptions();
    qo.setBatchSize(new Integer(3));
    binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "QueryOptions", qo);
    try {
        qr = binding.query("select id, Website, Name from Account where Name = 'Golden Straw'");
        ArrayList records = this.loadQueryResults(qr);
        if (records.size() != 0) {
            HashMap record = (HashMap) records.get(0);
            System.out.println("Retrieved " + new Integer(records.size()).toString() + " account(s) using Name = 'Golden Straw', String = " + (record.containsKey("id") ? record.get("id").toString() : " ").toString() + ", website = " + (record.containsKey("website") ? record.get("website").toString() : " ").toString());
        }
        // if (qr.getSize() != 0) {
        // SObject account = qr.getRecords()[0];
        //
        // System.out.println("Retrieved "
        // + new Integer(qr.getSize()).toString()
        // + " account(s) using Name = 'Golden Straw', String = "
        // + account.getId() + ", website = "
        // + account.get_any()[1]);
        // }
        qr = binding.query("select FirstName, LastName from Contact");
        int loopCount = 0;
        boolean continueLoop = true;
        while (continueLoop) {
            System.out.println("Results set " + new Integer(loopCount++).toString() + " - ");
            // process the query results
            for (int i = 0; i < qr.getRecords().length; i++) {
                SObject con = qr.getRecords()[i];
                String fName = "";
                String lName = "";
                if (con.get_any()[0].getName().toLowerCase().equals("firstname")) {
                    fName = con.get_any()[0].getValue();
                    lName = con.get_any()[1].getValue();
                } else
                    lName = con.get_any()[0].getValue();
                if (fName == null) {
                    System.out.println("Contact " + (i + 1) + ": " + lName);
                } else {
                    System.out.println("Contact " + (i + 1) + ": " + fName + " " + lName);
                }
            }
            // recent queryResult
            if (qr.isDone())
                continueLoop = false;
            else
                qr = binding.queryMore(qr.getQueryLocator());
        }
        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) SforceServiceLocator(com.salesforce.soap.partner.SforceServiceLocator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SObject(com.salesforce.soap.partner.sobject.SObject) QueryOptions(com.salesforce.soap.partner.QueryOptions) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 2 with QueryOptions

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

the class SforceManagementImpl method queryAll.

@Override
public QueryResult queryAll(String soql, int batchSize) throws Exception {
    QueryAll queryAll = new QueryAll();
    queryAll.setQueryString(soql);
    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setBatchSize(batchSize);
    QueryResult qr = sforceConn.queryAll(queryAll, queryOptions).getResult();
    return qr;
}
Also used : QueryResult(com.salesforce.soap.partner.QueryResult) QueryAll(com.salesforce.soap.partner.QueryAll) QueryOptions(com.salesforce.soap.partner.QueryOptions)

Example 3 with QueryOptions

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

the class SforceManagementImpl method queryMore.

@Override
public QueryResult queryMore(QueryLocator queryLocator, int batchSize) throws Exception {
    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setBatchSize(batchSize);
    QueryMore queryMore = new QueryMore();
    queryMore.setQueryLocator(queryLocator);
    QueryResult qr = sforceConn.queryMore(queryMore, queryOptions).getResult();
    return qr;
}
Also used : QueryMore(com.salesforce.soap.partner.QueryMore) QueryResult(com.salesforce.soap.partner.QueryResult) QueryOptions(com.salesforce.soap.partner.QueryOptions)

Example 4 with QueryOptions

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

the class SforceManagementImpl method query.

@Override
public QueryResult query(String soql, int batchSize) throws Exception {
    Query query = new Query();
    query.setQueryString(soql);
    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setBatchSize(batchSize);
    QueryResult qr = sforceConn.query(query, queryOptions).getResult();
    return qr;
}
Also used : QueryResult(com.salesforce.soap.partner.QueryResult) Query(com.salesforce.soap.partner.Query) QueryOptions(com.salesforce.soap.partner.QueryOptions)

Aggregations

QueryOptions (com.salesforce.soap.partner.QueryOptions)4 QueryResult (com.salesforce.soap.partner.QueryResult)4 Query (com.salesforce.soap.partner.Query)1 QueryAll (com.salesforce.soap.partner.QueryAll)1 QueryMore (com.salesforce.soap.partner.QueryMore)1 SforceServiceLocator (com.salesforce.soap.partner.SforceServiceLocator)1 ApiFault (com.salesforce.soap.partner.fault.ApiFault)1 SObject (com.salesforce.soap.partner.sobject.SObject)1 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ServiceException (javax.xml.rpc.ServiceException)1