2

I need to get documents of a particular library using SOQL.

SELECT title FROM ContentVersion where Contendocument.Parent.Contentworkspace.name='EMEA Sales'

The error i get is INVALID_FIELD: on Contendocument.Parent.Contentworkspace.name

The ERD model for content objects can be viewed here http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_content.htm

2 Answers 2

7

The following worked for me:

ID workspaceId = [SELECT Id FROM ContentWorkspace WHERE Name = 'EMEA Sales'][0].Id;
List <ContentVersion> allDocuments = [SELECT Title FROM ContentVersion WHERE ContentDocument.ParentId = :workspaceId]);
4

Retrieving documents from a library using filter like

[SELECT Title FROM ContentVersion WHERE ContentDocument.ParentId = :workspaceId]

may be incorrect, if document is shared with several libraries, and workspaceId is not equal to the library it was initially uploaded to.

Example: Doc1 was uploaded in Library1, and then shared with Libary2. If you use Libary2.Id as workspaceId in the query above, it will return 0 results, because ContentDocument.ParentId will be equal to Library1.Id.

Document and Library sharing dependencies can be viewed in ContentWorkspaceDoc object. So I would try this query:

[SELECT Title 
 FROM ContentVersion 
 WHERE ContentDocumentId in (SELECT ContentDocumentId 
                             FROM ContentWorkspaceDoc 
                             WHERE ContentWorkspaceId = :workspaceId
                              )
]

If you need to export all document versions, you can look at this solution.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .