You need to sign in to do that
Don't have an account?
Content API: VersionData field of ContentVersion object causing low-level errors
I've written some very simple Java code to query the the ContentVersion object.
If I don't include the VersionData field everything works fine. If I include the VersionData field, I get the following low-level error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
n at com.sforce.soap.partner.QueryResult.getRecords(QueryResult.java:94)
at net.xxx.salesforce.content.ContentSynch.listContent(ContentSynch.java:176)
at net.xxx.salesforce.content.ContentSynch.run(ContentSynch.java:91)
at net.xxx.salesforce.content.ContentSynch.main(ContentSynch.java:68)
It's actually failing in code generated from the Partner WSDL:
public com.sforce.soap.partner.sobject.SObject getRecords(int i) {
return this.records[i];
}
I'm going against a Trial Org with 2 Powerpoint presentations.
Any ideas on what might be going wrong? Again, if I remove the VersionData field everything is fine.
Code:
-----------------------------------------------------
//Note: for some reason API fails when you try to query Language, RecordTypeId
String soql = "Select " +
"Id," +
"ContentDocumentId, " +
"ContentModifiedById," +
"ContentModifiedDate," +
"ContentSize," +
"ContentUrl," +
"CreatedById," +
"Description," +
"FeaturedContentBoost," +
"FeaturedContentDate," +
"FileType," +
"FirstPublishLocationId," +
"IsLatest," +
"NegativeRatingCount," +
"OwnerId," +
"PathOnClient," +
"PositiveRatingCount," +
"PublishStatus," +
"RatingCount," +
"ReasonForChange," +
"TagCsv," +
"Title," +
"VersionData," +
"VersionNumber " +
"from ContentVersion";
logger.debug("Query: " + soql);
try {
qr = _binding.query(soql);
logger.debug("Records returned: " + qr.getSize());
}
catch (RemoteException ex) {
logger.error("Content Query failed: " + ex.getMessage());
System.exit(-1);
}
return qr;
}
void listContent(QueryResult qr) {
//loop through until all records have been retrieved
boolean done = false;
while(!done) {
for(int i = 0; i < qr.getSize(); i++) {
logger.debug("i is " + i);
logger.debug("qr.getSize() is " + qr.getSize());
logger.debug(qr.getRecords(i).getId()); //BOOM!
}
if (qr.isDone()) {
done = true;
}
else {
try {
qr = _binding.queryMore(qr.getQueryLocator());
}
catch (RemoteException ex) {
logger.error(ex.getMessage());
}
}
}
}
All Answers
Simon,
Thanks once again for your expertise here.
My syntax was indeed imprecise. I should have used "i < qr.getRecords().length" as the limiting condition in the loop. Once I made this change, all works as expected.
Much appreciated.