@SuppressWarnings("ReuseOfLocalVariable") @Test public void testRetrieveExtended() throws ApiException { List<Id> ids = new ArrayList<Id>(); ids.add(new Id("0035000000km1oh")); ids.add(new Id("0035000000km1oi")); ids.add(new Id("0035000000km1oj")); ids.add(new Id("0035000000km1ok")); ids.add(new Id("0035000000km1ol")); List<String> fields = new ArrayList<String>(); fields.add("FirstName"); fields.add("LastName"); fields.add("Department"); fields.add("Email"); fields.add("Title"); Map<Id, SObject> results = this.conn.retrieveExtended("Contact", ids, fields, 12); assertEquals(5, results.size()); SObject s = results.get(ids.get(0)); assertEquals("Rose", s.getField("FirstName")); assertEquals("Gonzalez", s.getField("LastName")); assertEquals("Procurement", s.getField("Department")); assertEquals("rose@edge.com", s.getField("Email")); assertEquals("SVP, Procurement", s.getField("Title")); s = results.get(ids.get(1)); assertEquals("Sean", s.getField("FirstName")); assertEquals("Forbes", s.getField("LastName")); assertEquals("Finance", s.getField("Department")); assertEquals("sean@edge.com", s.getField("Email")); assertEquals("CFO", s.getField("Title")); s = results.get(ids.get(2)); assertEquals("Jack", s.getField("FirstName")); assertEquals("Rogers", s.getField("LastName")); assertNull(s.getField("Department")); assertEquals("jrogers@burlington.com", s.getField("Email")); assertEquals("VP, Facilities", s.getField("Title")); s = results.get(ids.get(3)); assertEquals("Pat", s.getField("FirstName")); assertEquals("Stumuller", s.getField("LastName")); assertEquals("Finance", s.getField("Department")); assertEquals("pat@pyramid.net", s.getField("Email")); assertEquals("SVP, Administration and Finance", s.getField("Title")); s = results.get(ids.get(4)); assertEquals("Andy", s.getField("FirstName")); assertEquals("Young", s.getField("LastName")); assertEquals("Internal Operations", s.getField("Department")); assertEquals("a_young@dickenson.com", s.getField("Email")); assertEquals("SVP, Operations", s.getField("Title")); }
@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);  }