public XmlObject[] getElements() throws Exception { // Query first this.qr = getBinding().query( getSQL() ); // and then return records SObject con = getQueryResult().getRecords()[0]; if ( con == null ) { return null; } return getChildren( con ); }
default: this.qr = isQueryAll() ? getBinding().queryAll( getSQL() ) : getBinding().query( getSQL() ); this.sObjects = getQueryResult().getRecords(); this.queryResultSize = getQueryResult().getSize();
@Override public void execute() throws BuildException { try { PartnerConnection pc = ConnectionFactory.getPartnerConnection(getConfig()); String soql = String.format(FORMAT_SOQL, objectApiName); QueryResult qr = pc.query(soql); Boolean done = false; log(String.format(FORMAT_DELETE_MSG, qr.getSize(), objectApiName)); if (qr.getSize() > 0) { while (!done) { com.sforce.soap.partner.sobject.SObject[] records = qr.getRecords(); String[] ids = new String[records.length]; for (int i = 0; i<records.length; ++i) { ids[i] = (String)records[i].getField("Id"); } pc.delete(ids); if (qr.isDone()) { done = true; } else { qr = pc.queryMore(qr.getQueryLocator()); } } } } catch (ConnectionException e) { handleException(e); } }
@Override public com.sforce.soap.partner.IQueryResult query(java.lang.String queryString) throws com.sforce.ws.ConnectionException { return connection.query( queryString); }
protected QueryResult executeSalesforceQuery() throws IOException, ConnectionException { TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties; getConnection().setQueryOptions(inProperties.batchSize.getValue()); if (inProperties.includeDeleted.getValue()) { return getConnection().queryAll(getQueryString(inProperties)); } else { return getConnection().query(getQueryString(inProperties)); } }
private QueryResult executeSoqlQuery(String query) { logger.info("Executing SOQL query: {}", query); try { QueryResult queryResult = _connection.query(query); return queryResult; } catch (ConnectionException e) { throw SalesforceUtils.wrapException(e, "Failed to invoke query service"); } }
protected QueryResult executeSalesforceQuery() throws IOException, ConnectionException { TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties; getConnection().setQueryOptions(inProperties.batchSize.getValue()); if (inProperties.includeDeleted.getValue()) { return getConnection().queryAll(getQueryString(inProperties)); } else { return getConnection().query(getQueryString(inProperties)); } }
private QueryResult executeSoqlQuery(String query) { logger.info("Executing SOQL query: {}", query); try { QueryResult queryResult = _connection.query(query); return queryResult; } catch (ConnectionException e) { throw SalesforceUtils.wrapException(e, "Failed to invoke query service"); } }
protected QueryResult executeSalesforceQuery() throws IOException, ConnectionException { TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties; getConnection().setQueryOptions(inProperties.batchSize.getValue()); if (inProperties.includeDeleted.getValue()) { return getConnection().queryAll(getQueryString(inProperties)); } else { return getConnection().query(getQueryString(inProperties)); } }
private QueryResult executeSoqlQuery(String query) { logger.info("Executing SOQL query: {}", query); try { QueryResult queryResult = _connection.query(query); return queryResult; } catch (ConnectionException e) { throw SalesforceUtils.wrapException(e, "Failed to invoke query service"); } }
public static String fetchApexTestClassNameFromId(PartnerConnection connection, String apexClassId) { String apexClassName = ""; String soql = QueryConstructor.generateQueryToFetchApexClassFromId(apexClassId); QueryResult queryResult = null; try { queryResult = connection.query(soql); } catch (ConnectionException e) { ApexUnitUtils.shutDownWithDebugLog(e, ConnectionHandler .logConnectionException(e, connection, soql)); } if (queryResult != null && queryResult.getDone()) { SObject[] sObjects = queryResult.getRecords(); for (SObject sobject : sObjects) { if (sobject != null) { apexClassName = sobject.getField("Name").toString(); LOG.info("Fetched the Apex test class for Id: " + apexClassId + " : " + apexClassName); if (!apexClassMap.containsKey(apexClassId)) { apexClassMap.put(apexClassId, apexClassName); } } } } return apexClassName; }
public String getParentJobIdForTestQueueItems(List<SaveResult> bulkResults, PartnerConnection conn) { String parentJobId = null; if (bulkResults != null && bulkResults.size() > 0) { SaveResult sr = bulkResults.get(0); String testQueueItemId = sr.getId(); String soql = QueryConstructor.fetchParentJobIdForApexTestQueueItem(testQueueItemId); LOG.debug("Query used for fetching parent job ID for bulk results: " + soql); QueryResult queryResult = null; try{ queryResult = conn.query(soql); }catch (ConnectionException e) { ApexUnitUtils.shutDownWithDebugLog(e, ConnectionHandler .logConnectionException(e, conn, soql)); } if (queryResult.isDone()) { // TODO: We need to verify what's the limit of records that the // bulk api can insert in one transaction. multiple transactions // mean multiple parent job ids parentJobId = fetchParentJobId(queryResult); LOG.info("Async test parent job Id : " + parentJobId); } } else { ApexUnitUtils.shutDownWithErrMsg("Invalid bulk results. No bulk results returned."); } return parentJobId; }
public static String[] constructClassIdArrayUsingWSC(PartnerConnection connection, String soql) { String[] classIdsAsArray = null; QueryResult queryResult = null; try { queryResult = connection.query(soql); } catch (ConnectionException e) { ApexUnitUtils.shutDownWithDebugLog(e, ConnectionHandler .logConnectionException(e, connection, soql)); } if (queryResult != null) { classIdsAsArray = fetchApexClassesAsArray(queryResult); } else { ApexUnitUtils.shutDownWithErrMsg("Faulty query performed using the soql Query " + soql + " returned incorrect result. Halting the application"); } return classIdsAsArray; }
public static String fetchAndAddToMapApexClassIdBasedOnName(PartnerConnection connection, String soqlBasedOnName) { String apexClassId = null; QueryResult queryResult = null; try { queryResult = connection.query(soqlBasedOnName); } catch (ConnectionException e) { ApexUnitUtils.shutDownWithDebugLog(e, ConnectionHandler .logConnectionException(e, connection, soqlBasedOnName)); } if (queryResult != null && queryResult.getDone()) { String[] classIds = fetchApexClassesAsArray(queryResult); if(classIds!=null && classIds.length>0){ apexClassId = classIds[0]; } } return apexClassId; }
@Override public void execute() throws BuildException { checkAttributes(); // prepare where clause try { SalesforceConfig conf = getConfig(); PartnerConnection connection = ConnectionFactory.getPartnerConnection(conf); log(String.format("Getting RecordTypeId: %s.%s", object, developerName)); QueryResult result = connection.query(getCompiledQuery()); if (result.getSize() == 1) { String value = (String) result.getRecords()[0].getField("Id"); getProject().setNewProperty(propertyRef, value); } else { throw new BuildException("Unable to find a unique result"); } } catch (ConnectionException e) { throw new BuildException(e.getLocalizedMessage()); } }
@Override public void execute() throws BuildException { try { PartnerConnection pc = ConnectionFactory.getPartnerConnection(getConfig()); QueryResult result = pc.query(SOQL_JOBS()); if (result!=null && result.getSize() > 0) { log(String.format("Clearing %d scheduled jobs...", result.getSize())); SoapConnection tc = ConnectionFactory.getToolingConnection(pc, getConfig()); for (SObject o : result.getRecords()) { String jobId = (String) o.getId(); log("Aborting Job: " + jobId); executeApex(tc, String.format(APEX_ABORT, jobId)); } } else { log("No scheduled job found"); } } catch (ConnectionException e) { handleException(e); } catch (Exception e) { log(e.getMessage()); } } }
/** * Locates this object in the datastore. * * @param op The ObjectProvider for the object to be found */ @Override public void locateObject(ObjectProvider op) { ForceManagedConnection mconn = (ForceManagedConnection) storeManager.getConnection(op.getExecutionContext()); try { AbstractClassMetaData acmd = op.getClassMetaData(); TableImpl table = storeManager.getTable(acmd); QueryResult qr = ((PartnerConnection) mconn.getConnection()) .query("select count() from " + table.getTableName().getForceApiName() + " where id='" + op.provideField(op.getClassMetaData().getPKMemberPositions()[0]) + "'"); if (qr.getSize() == 0) { throw new NucleusObjectNotFoundException(); } } catch (ConnectionException x) { throw new NucleusDataStoreException(x.getMessage(), x); } finally { mconn.release(); } }
this.table = storeManager.getTable(objectProvider.getClassMetaData()); if (pkValue != null) { QueryResult qr = ((PartnerConnection) mconn.getConnection()).query( new ForceQueryUtils(objectProvider.getExecutionContext(), mconn, null, null, null, null) .buildQueryWithPK(table, objectProvider.getClassMetaData(), fieldNumbers, (String) pkValue, 0));
this.table = storeManager.getTable(objectProvider.getClassMetaData()); if (pkValue != null) { QueryResult qr = ((PartnerConnection) mconn.getConnection()).query( new ForceQueryUtils(objectProvider.getExecutionContext(), mconn, null, null, null, null) .buildQueryWithPK(table, objectProvider.getClassMetaData(), fieldNumbers, (String) pkValue, 0));
/** * Locates this object in the datastore. * * @param op The ObjectProvider for the object to be found */ @Override public void locateObject(ObjectProvider op) { ForceManagedConnection mconn = (ForceManagedConnection) storeManager.getConnection(op.getExecutionContext()); try { AbstractClassMetaData acmd = op.getClassMetaData(); TableImpl table = storeManager.getTable(acmd); QueryResult qr = ((PartnerConnection) mconn.getConnection()) .query("select count() from " + table.getTableName().getForceApiName() + " where id='" + op.provideField(op.getClassMetaData().getPKMemberPositions()[0]) + "'"); if (qr.getSize() == 0) { throw new NucleusObjectNotFoundException(); } } catch (ConnectionException x) { throw new NucleusDataStoreException(x.getMessage(), x); } finally { mconn.release(); } }