Search in sources :

Example 11 with QueryResult

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

use of com.salesforce.soap.partner.QueryResult 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 13 with QueryResult

use of com.salesforce.soap.partner.QueryResult 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 14 with QueryResult

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

the class TopRecord method processOMElement.

private void processOMElement(OMElement ome, String prefixName) throws Exception {
    if (ome.getChildElements().hasNext()) {
        Iterator iter = ome.getChildElements();
        // delete the fixed id and type elements when find firstly
        int typeCount = 0;
        int idCount = 0;
        while (iter.hasNext()) {
            Object objectValue = iter.next();
            if (objectValue != null) {
                if (objectValue instanceof OMElement) {
                    OMElement omeElem = (OMElement) objectValue;
                    if ("type".equals(omeElem.getLocalName()) && typeCount == 0) {
                        typeCount++;
                        continue;
                    }
                    if ("Id".equals(omeElem.getLocalName()) && idCount == 0) {
                        idCount++;
                        continue;
                    }
                    processOMElement(omeElem, prefixName + TopConfig.COLUMNNAME_DELIMTER + ome.getLocalName());
                } else if (objectValue instanceof SObject) {
                    SObject sobject = (SObject) objectValue;
                    processSObject(sobject, prefixName + TopConfig.COLUMNNAME_DELIMTER + sobject.getType());
                } else if (objectValue instanceof QueryResult) {
                    QueryResult queryResult = (QueryResult) objectValue;
                    processQueryResult(queryResult, prefixName);
                } else {
                    throw new Exception("Unexcepted case happend...");
                }
            }
        }
    } else {
        if (ome.getText() == null || "".equals(ome.getText())) {
            return;
        }
        String newPrefixName = prefixName + TopConfig.COLUMNNAME_DELIMTER + ome.getLocalName();
        // add the columnName to List one by one(order is important)
        if (!columnNameList.contains(newPrefixName)) {
            columnNameList.add(newPrefixName);
        }
        if (!columnLocalNameList.contains(ome.getLocalName())) {
            columnLocalNameList.add(ome.getLocalName());
        }
        Object value = valueMap.get(newPrefixName);
        if (value != null) {
            valueMap.put(newPrefixName, value + TopConfig.VALUE_DELIMITER + ome.getText());
        } else {
            valueMap.put(newPrefixName, ome.getText());
        }
    }
}
Also used : QueryResult(com.salesforce.soap.partner.QueryResult) Iterator(java.util.Iterator) SObject(com.salesforce.soap.partner.sobject.SObject) SObject(com.salesforce.soap.partner.sobject.SObject) OMElement(org.apache.axiom.om.OMElement)

Example 15 with QueryResult

use of com.salesforce.soap.partner.QueryResult 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

QueryResult (com.salesforce.soap.partner.QueryResult)15 SObject (com.salesforce.soap.partner.sobject.SObject)10 RemoteException (java.rmi.RemoteException)9 IOException (java.io.IOException)7 ServiceException (javax.xml.rpc.ServiceException)7 ApiFault (com.salesforce.soap.partner.fault.ApiFault)6 QueryOptions (com.salesforce.soap.partner.QueryOptions)4 SforceServiceLocator (com.salesforce.soap.partner.SforceServiceLocator)2 HashMap (java.util.HashMap)2 DescribeSObjectResult (com.salesforce.soap.partner.DescribeSObjectResult)1 LoginResult (com.salesforce.soap.partner.LoginResult)1 Query (com.salesforce.soap.partner.Query)1 QueryAll (com.salesforce.soap.partner.QueryAll)1 QueryMore (com.salesforce.soap.partner.QueryMore)1 ResetPasswordResult (com.salesforce.soap.partner.ResetPasswordResult)1 SearchRecord (com.salesforce.soap.partner.SearchRecord)1 SearchResult (com.salesforce.soap.partner.SearchResult)1 SessionHeader (com.salesforce.soap.partner.SessionHeader)1 SetPasswordResult (com.salesforce.soap.partner.SetPasswordResult)1 UpsertResult (com.salesforce.soap.partner.UpsertResult)1