@Test public void testRetrieveExtendedRethrowsRetrieveException() { List<Id> ids = new ArrayList<Id>(); ids.add(new Id("0034000000QnQVPAA3")); List<String> fields = new ArrayList<String>(); fields.add("BadFieldName"); try { this.conn.retrieveExtended("Contact", ids, fields, 12); fail(); } catch (ApiException e) { assertEquals("Couldn't retrieve a field name chunk", e.getMessage()); Throwable t = e.getCause(); assertTrue(t instanceof ApiException); ApiException inner = (ApiException) t; assertEquals("Invalid field", inner.getMessage()); assertEquals(ExceptionCode.INVALID___FIELD, inner.getApiFaultCode()); assertEquals("\nSELECT BadFieldName FROM Contact\n ^\n" + "ERROR at Row:1:Column:8\n" + "No such column 'BadFieldName' on entity 'Contact'. " + "If you are attempting to use a custom field, be sure to " + "append the '__c' after the custom field name. Please reference " + "your WSDL or the describe call for the appropriate names.", inner.getApiFaultMessage()); assertNotSame(inner, e); } }
@Nonnull @Override public synchronized Map<Id, SObject> retrieveExtended(@Nonnull String sObjectType, @Nonnull List<Id> ids, @Nonnull List<String> fields, int maxFieldNameChunkSize) throws ApiException { Map<Id, SObject> inProgressMap = new HashMap<Id, SObject>(); for (Id id : ids) { inProgressMap.put(id, PartnerSObjectImpl.getNewWithId(sObjectType, id)); } List<List<String>> fieldNameChunks = ConnectionUtils.splitFieldList(fields, maxFieldNameChunkSize); List<Id> idList; for (List<String> fieldListChunk : fieldNameChunks) { idList = new ArrayList<Id>(inProgressMap.keySet()); List<SObject> retrievedSObjects; try { retrievedSObjects = this.retrieve(sObjectType, idList, fieldListChunk); } catch (ApiException e) { throw this.getApiExceptionWithCause("Couldn't retrieve a field name chunk", e); } if (retrievedSObjects.size() != idList.size()) { throw ApiException.getNew("Not all Ids had records retrieved", this.getUsername()); } Iterator<SObject> retrievedSObjIter = retrievedSObjects.iterator(); Iterator<Id> idIter = idList.iterator(); SObject retrievedSObj; Id currentId; while (retrievedSObjIter.hasNext()) { retrievedSObj = retrievedSObjIter.next(); currentId = idIter.next(); if (retrievedSObj == null) { logger.info("Could not retrieve for id <" + currentId + ">: got back null. Removing from the in progress map. This can mean" + " that field permissions are set wrong or that the fields selected" + " have caused an internal error on Salesforce's side, perhaps because " + "the generated SQL exceeded their Oracle install's max query length."); inProgressMap.remove(currentId); retrievedSObjIter.remove(); } } for (SObject retrievedCopy : retrievedSObjects) { SObject inProgressCopy = inProgressMap.get(retrievedCopy.getId()); if (inProgressCopy == null) { throw ApiException .getNew("Somehow got an SObject back from retrieve() with an Id that we did not ask for", this.getUsername()); } inProgressCopy.setAllFields(retrievedCopy.getAllFields()); } } return inProgressMap; }
PartnerConnectionImpl extends AbstractSalesforceConnection implements PartnerConnection { @Nonnull @Override public synchronized Map<Id, SObject> retrieveExtended(@Nonnull String sObjectType, @Nonnull List<Id> ids, @Nonnull List<String> fields, int maxFieldNameChunkSize) throws ApiException { Map<Id, SObject> inProgressMap = new HashMap<Id, SObject>(); for (Id id : ids) { inProgressMap.put(id, PartnerSObjectImpl.getNewWithId(sObjectType, id)); } List<List<String>> fieldNameChunks = ConnectionUtils.splitFieldList(fields, maxFieldNameChunkSize); List<Id> idList; for (List<String> fieldListChunk : fieldNameChunks) { idList = new ArrayList<Id>(inProgressMap.keySet()); List<SObject> retrievedSObjects; try { retrievedSObjects = this.retrieve(sObjectType, idList, fieldListChunk); } catch (ApiException e) { throw this.getApiExceptionWithCause("Couldn't retrieve a field name chunk", e); } if (retrievedSObjects.size() != idList.size()) { throw ApiException.getNew("Not all Ids had records retrieved", this.getUsername()); } Iterator<SObject> retrievedSObjIter = retrievedSObjects.iterator(); Iterator<Id> idIter = idList.iterator(); SObject retrievedSObj; Id currentId; while (retrievedSObjIter.hasNext()) { retrievedSObj = retrievedSObjIter.next(); currentId = idIter.next(); if (retrievedSObj == null) { logger.info("Could not retrieve for id <" + currentId + ">: got back null. Removing from the in progress map. This can mean" + " that field permissions are set wrong or that the fields selected" + " have caused an internal error on Salesforce's side, perhaps because " + "the generated SQL exceeded their Oracle install's max query length."); inProgressMap.remove(currentId); retrievedSObjIter.remove(); } } for (SObject retrievedCopy : retrievedSObjects) { SObject inProgressCopy = inProgressMap.get(retrievedCopy.getId()); if (inProgressCopy == null) { throw ApiException .getNew("Somehow got an SObject back from retrieve() with an Id that we did not ask for", this.getUsername()); } inProgressCopy.setAllFields(retrievedCopy.getAllFields()); } } return inProgressMap; } }
PartnerConnectionImpl extends AbstractSalesforceConnection implements PartnerConnection { @Nonnull @Override public synchronized Map<Id, SObject> retrieveExtended(@Nonnull String sObjectType, @Nonnull List<Id> ids, @Nonnull List<String> fields, int maxFieldNameChunkSize) throws ApiException { Map<Id, SObject> inProgressMap = new HashMap<Id, SObject>(); for (Id id : ids) { inProgressMap.put(id, PartnerSObjectImpl.getNewWithId(sObjectType, id)); } List<List<String>> fieldNameChunks = ConnectionUtils.splitFieldList(fields, maxFieldNameChunkSize); List<Id> idList; for (List<String> fieldListChunk : fieldNameChunks) { idList = new ArrayList<Id>(inProgressMap.keySet()); List<SObject> retrievedSObjects; try { retrievedSObjects = this.retrieve(sObjectType, idList, fieldListChunk); } catch (ApiException e) { throw this.getApiExceptionWithCause("Couldn't retrieve a field name chunk", e); } if (retrievedSObjects.size() != idList.size()) { throw ApiException.getNew("Not all Ids had records retrieved", this.getUsername()); } Iterator<SObject> retrievedSObjIter = retrievedSObjects.iterator(); Iterator<Id> idIter = idList.iterator(); SObject retrievedSObj; Id currentId; while (retrievedSObjIter.hasNext()) { retrievedSObj = retrievedSObjIter.next(); currentId = idIter.next(); if (retrievedSObj == null) { logger.info("Could not retrieve for id <" + currentId + ">: got back null. Removing from the in progress map. This can mean" + " that field permissions are set wrong or that the fields selected" + " have caused an internal error on Salesforce's side, perhaps because " + "the generated SQL exceeded their Oracle install's max query length."); inProgressMap.remove(currentId); retrievedSObjIter.remove(); } } for (SObject retrievedCopy : retrievedSObjects) { SObject inProgressCopy = inProgressMap.get(retrievedCopy.getId()); if (inProgressCopy == null) { throw ApiException .getNew("Somehow got an SObject back from retrieve() with an Id that we did not ask for", this.getUsername()); } inProgressCopy.setAllFields(retrievedCopy.getAllFields()); } } return inProgressMap; } private  PartnerConnectionImpl(@Nonnull CallSemaphore semaphore, @Nonnull ConnectionBundleImpl bundle,
            MetricRegistry metricRegistry); }
PartnerConnectionImpl extends AbstractSalesforceConnection implements PartnerConnection { @Nonnull @Override public synchronized Map<Id, SObject> retrieveExtended(@Nonnull String sObjectType, @Nonnull List<Id> ids, @Nonnull List<String> fields, int maxFieldNameChunkSize) throws ApiException { Map<Id, SObject> inProgressMap = new HashMap<Id, SObject>(); for (Id id : ids) { inProgressMap.put(id, PartnerSObjectImpl.getNewWithId(sObjectType, id)); } List<List<String>> fieldNameChunks = ConnectionUtils.splitFieldList(fields, maxFieldNameChunkSize); List<Id> idList; for (List<String> fieldListChunk : fieldNameChunks) { idList = new ArrayList<Id>(inProgressMap.keySet()); List<SObject> retrievedSObjects; try { retrievedSObjects = this.retrieve(sObjectType, idList, fieldListChunk); } catch (ApiException e) { throw this.getApiExceptionWithCause("Couldn't retrieve a field name chunk", e); } if (retrievedSObjects.size() != idList.size()) { throw ApiException.getNew("Not all Ids had records retrieved", this.getUsername()); } Iterator<SObject> retrievedSObjIter = retrievedSObjects.iterator(); Iterator<Id> idIter = idList.iterator(); SObject retrievedSObj; Id currentId; while (retrievedSObjIter.hasNext()) { retrievedSObj = retrievedSObjIter.next(); currentId = idIter.next(); if (retrievedSObj == null) { logger.info("Could not retrieve for id <" + currentId + ">: got back null. Removing from the in progress map. This can mean" + " that field permissions are set wrong or that the fields selected" + " have caused an internal error on Salesforce's side, perhaps because " + "the generated SQL exceeded their Oracle install's max query length."); inProgressMap.remove(currentId); retrievedSObjIter.remove(); } } for (SObject retrievedCopy : retrievedSObjects) { SObject inProgressCopy = inProgressMap.get(retrievedCopy.getId()); if (inProgressCopy == null) { throw ApiException .getNew("Somehow got an SObject back from retrieve() with an Id that we did not ask for", this.getUsername()); } inProgressCopy.setAllFields(retrievedCopy.getAllFields()); } } return inProgressMap; } private  PartnerConnectionImpl(@Nonnull CallSemaphore semaphore, @Nonnull ConnectionBundleImpl bundle,
            MetricRegistry metricRegistry); @Override synchronized int count(@Nonnull String sObjectType, @Nonnull String condition); @Override synchronized int count(@Nonnull String sObjectType); @Override synchronized int countAll(@Nonnull String sObjectType, @Nonnull String condition); @Override synchronized int countAll(@Nonnull String sObjectType); @Nonnull @Override synchronized List<SaveResult> create(@Nonnull List<SObject> sObjects); @Nonnull @Override synchronized List<DeleteResult> delete(@Nonnull List<Id> ids); @Nonnull @Override synchronized DescribeGlobalResult describeGlobal(); @Nonnull @Override synchronized SObjectDescription describeSObject(@Nonnull String sObjectType); @Nonnull @Override synchronized List<SObjectDescription> describeSObjects(@Nonnull List<String> sObjectTypes); @Nonnull @Override synchronized List<EmptyRecycleBinResult> emptyRecycleBin(@Nonnull List<Id> ids); @Nonnull @Override synchronized DateTime getServerTimestamp(); @Nonnull @Override synchronized UserInfo getUserInfo(); @Nonnull @Override synchronized PartnerQueryResult query(@Nonnull String queryStr); @Nonnull @Override synchronized PartnerQueryResult queryAll(@Nonnull String queryStr); @Nonnull @Override synchronized PartnerQueryResult queryMore(@Nonnull PartnerQueryLocator locator); @Nonnull @Override synchronized List<SObject> retrieve(@Nonnull String sObjectType, @Nonnull List<Id> ids,
            @Nonnull List<String> fieldList); @Nonnull @Override synchronized Map<Id, SObject> retrieveExtended(@Nonnull String sObjectType, @Nonnull List<Id> ids,
            @Nonnull List<String> fields,
            int maxFieldNameChunkSize); @Nonnull @Override synchronized List<UndeleteResult> undelete(@Nonnull List<Id> ids); @Nonnull @Override synchronized List<SaveResult> update(@Nonnull List<SObject> sObjects); @Nonnull @Override synchronized List<UpsertResult> upsert(@Nonnull String externalIdFieldName, @Nonnull List<SObject> sObjects); }
PartnerConnectionImpl extends AbstractSalesforceConnection implements PartnerConnection { @Nonnull @Override public synchronized Map<Id, SObject> retrieveExtended(@Nonnull String sObjectType, @Nonnull List<Id> ids, @Nonnull List<String> fields, int maxFieldNameChunkSize) throws ApiException { Map<Id, SObject> inProgressMap = new HashMap<Id, SObject>(); for (Id id : ids) { inProgressMap.put(id, PartnerSObjectImpl.getNewWithId(sObjectType, id)); } List<List<String>> fieldNameChunks = ConnectionUtils.splitFieldList(fields, maxFieldNameChunkSize); List<Id> idList; for (List<String> fieldListChunk : fieldNameChunks) { idList = new ArrayList<Id>(inProgressMap.keySet()); List<SObject> retrievedSObjects; try { retrievedSObjects = this.retrieve(sObjectType, idList, fieldListChunk); } catch (ApiException e) { throw this.getApiExceptionWithCause("Couldn't retrieve a field name chunk", e); } if (retrievedSObjects.size() != idList.size()) { throw ApiException.getNew("Not all Ids had records retrieved", this.getUsername()); } Iterator<SObject> retrievedSObjIter = retrievedSObjects.iterator(); Iterator<Id> idIter = idList.iterator(); SObject retrievedSObj; Id currentId; while (retrievedSObjIter.hasNext()) { retrievedSObj = retrievedSObjIter.next(); currentId = idIter.next(); if (retrievedSObj == null) { logger.info("Could not retrieve for id <" + currentId + ">: got back null. Removing from the in progress map. This can mean" + " that field permissions are set wrong or that the fields selected" + " have caused an internal error on Salesforce's side, perhaps because " + "the generated SQL exceeded their Oracle install's max query length."); inProgressMap.remove(currentId); retrievedSObjIter.remove(); } } for (SObject retrievedCopy : retrievedSObjects) { SObject inProgressCopy = inProgressMap.get(retrievedCopy.getId()); if (inProgressCopy == null) { throw ApiException .getNew("Somehow got an SObject back from retrieve() with an Id that we did not ask for", this.getUsername()); } inProgressCopy.setAllFields(retrievedCopy.getAllFields()); } } return inProgressMap; } private  PartnerConnectionImpl(@Nonnull CallSemaphore semaphore, @Nonnull ConnectionBundleImpl bundle,
            MetricRegistry metricRegistry); @Override synchronized int count(@Nonnull String sObjectType, @Nonnull String condition); @Override synchronized int count(@Nonnull String sObjectType); @Override synchronized int countAll(@Nonnull String sObjectType, @Nonnull String condition); @Override synchronized int countAll(@Nonnull String sObjectType); @Nonnull @Override synchronized List<SaveResult> create(@Nonnull List<SObject> sObjects); @Nonnull @Override synchronized List<DeleteResult> delete(@Nonnull List<Id> ids); @Nonnull @Override synchronized DescribeGlobalResult describeGlobal(); @Nonnull @Override synchronized SObjectDescription describeSObject(@Nonnull String sObjectType); @Nonnull @Override synchronized List<SObjectDescription> describeSObjects(@Nonnull List<String> sObjectTypes); @Nonnull @Override synchronized List<EmptyRecycleBinResult> emptyRecycleBin(@Nonnull List<Id> ids); @Nonnull @Override synchronized DateTime getServerTimestamp(); @Nonnull @Override synchronized UserInfo getUserInfo(); @Nonnull @Override synchronized PartnerQueryResult query(@Nonnull String queryStr); @Nonnull @Override synchronized PartnerQueryResult queryAll(@Nonnull String queryStr); @Nonnull @Override synchronized PartnerQueryResult queryMore(@Nonnull PartnerQueryLocator locator); @Nonnull @Override synchronized List<SObject> retrieve(@Nonnull String sObjectType, @Nonnull List<Id> ids,
            @Nonnull List<String> fieldList); @Nonnull @Override synchronized Map<Id, SObject> retrieveExtended(@Nonnull String sObjectType, @Nonnull List<Id> ids,
            @Nonnull List<String> fields,
            int maxFieldNameChunkSize); @Nonnull @Override synchronized List<UndeleteResult> undelete(@Nonnull List<Id> ids); @Nonnull @Override synchronized List<SaveResult> update(@Nonnull List<SObject> sObjects); @Nonnull @Override synchronized List<UpsertResult> upsert(@Nonnull String externalIdFieldName, @Nonnull List<SObject> sObjects);  }