[SalesForce] Creating Library Subfolders using ContentFolder & ContentFolderLink

I'm trying to create subfolders within my existing Salesforce libraries (ContentWorkspaces) & struggling with the apparent lack of documentation. I have 4 issues:

  1. Understanding how the hierarchy is structured
  2. Creating a ContentFolderLink
  3. Creating a ContentFolderLink before a root ContentFolder exists
  4. Enabling / checking that folders are enabled for my ContentWorkspace

Question 1

Am I right in thinking that the hierarchy should look like:


Question 2

Based on the description for the ContentFolderLink object in the release notes


In a ContentWorkspace that has folders enabled, defines the association between the ContentWorkspace and its root ContentFolder.

I need to create a ContentFolderLink, in order to create a ContentFolder subfolder.

When I try to create a ContentFolderLink

ContentWorkspace cw = [SELECT Id,Name
                         FROM ContentWorkspace
                        WHERE Name = 'Library Name'];

ContentFolderLink cfl = new ContentFolderLink(ParentEntityId=cw.Id);
Insert cfl;

it causes an error

Field is not writeable: ContentFolderLink.ParentEntityId

how should I resolve this?

Question 3

I expect I need to create a ContentFolder before I create the ContentFolderLink so that I have an Id for the ContentFolderLink's ContentFolderId field, however when I try to create the folder

ContentWorkspace cw = [SELECT Id,Name
                         FROM ContentWorkspace
                        WHERE Name = 'Library Name'];

ContentFolder cf = new ContentFolder(Name='Subfolder',ParentContentFolderId=cw.Id);
Insert cf;

it causes an error

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Parent Content Folder ID: id value of incorrect type: 0585400000058bZAAQ: [ParentContentFolderId]

I assume that I should be setting the ContentFolder's ParentContentFolderId as the ContentFolderLink but it won't have an Id until it's inserted, how should this sequence work?

Question 4

I would expect to see a boolean field for the object to indicate whether folders have been enabled for the library / ContentWorkspace but there isn't one listed in the API developer guide. How can I check / enable this setting?

Best Answer

I did raise a Case with the Salesforce support team & the Tier 3 team confirmed that the create operation is not supported for ContentFolderLinks & although they were able to create 2 folders, that were linked together via the ParentContentFolderId field, those folders were not visible in the Library UI.

However, I checked the Spring '17 release notes & it turns out that subfolders will be available for users to manage in Lightning Experience which solves my problem.

Related Topic