+ Start a Discussion

Error using SOQL query on Document when more than one document exists with the same name

Is this an issue with the Sforce API? This behavior occurs in my own code and also when using the SOQL Explorer (CSharp Partner Sample) tool.

If I have more than one Document with the same Name (they reside in different Folders), and I attempt to retrieve that Document with either of the following SOQL queries, the Sforce API thows the exception below.

Sample queries:

- Select id, Body from Document where Name = 'DuplicateFile.txt'
- Select id, Body from Document

Sforce exception:

Query failed: java.lang.RuntimeException: QueryStruct has not been saved to or loaded from the database!

Now if I query for a Document that has a unique name, everything works as expected.


I'm writing a routine to retrieve a Document by filename and foldername. My plan was to query on just the filename first, and if more than one Document is returned, I'd then run another query to retrieve the correct Folder Id. The idea is to avoid running two queries when I don't have to, yet when I also don't have the DocumentId or FolderId of the desired file. Thus, when files are uniquely named (which should be likely in the case I'm coding for) only one query would be necessary. Seem reasonable? But unless I can get multiple records back from the Document table, this won't work.

Any clues?


Hi HaroldH,

First, glad that the SOQL tool is useful for you.

It seems that the problem is on our side and the way to duplicate is just as you posted.  What is interesting is that if you do Select Id, name from Document where name = 'documentname', it will return both records.  I don't know if this will help you.  I will be filing a report on this and hopefully it will get fixed soon.



Can you also file a report for me? I'm using the query

SELECT Id, ParentId, Name, IsPrivate, BodyLength, Body, OwnerId, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp FROM Attachment

It only seems to happen for attachments. "QueryStruct has not been saved to or loaded from the database!"



Hi WhiZa,

This is the same error.  It seems when ever there is more than one record returned that contains a base64 field, the error occurs.  As a temporary work around, you can present all the info about an attachment or document and then go back to the fetch the actual document based on the user's selection (assuming there is a user looking at the query results).