function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MattMet86MattMet86 

Create ContentFolder in library

Anybody know how to create  a content folder? I have tried this command via the execute annonoymous window but I am getting back an incorrect ID for the parentContentFolderID field.  My ID is the chatter library ID. 
List<ContentFolder> folder = new List<ContentFolder>();
            folder.add(new ContentFolder(
                Name 					= 'HR Buzz',
                ParentContentFolderId 	= '05880000000PvIv'
            ));
        
        insert folder;

 
Andrew LokotoshAndrew Lokotosh
 On ContentFolder sObject  only Name field is required.  
So you easy can use that code to create new one!
 
List<ContentFolder> folder = new List<ContentFolder>();
            folder.add(new ContentFolder(
                Name 					= 'HR Buzz'
                
            ));
        
        insert folder;
But if you need to create hierarchy of folders you need to use already existed Record id.

Something like this.
 
String name ='your folder name';
ContentFolder folder  = [select  Id,  Name from ContentFolde Where Name=:name];

List<ContentFolder> folder = new List<ContentFolder>();
            folder.add(new ContentFolder(
                Name 					= 'HR Buzz',
                ParentContentFolderId 	= folder.id
            ));
        
        insert folder;

or
ContentFolder c = new ContentFolder(name = 'Parent');

List<ContentFolder> folder = new List<ContentFolder>();
            folder.add(new ContentFolder(
                Name 					= 'HR Buzz',
                ParentContentFolderId 	= c.id
            ));
        
        insert folder;
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentfolder.htm

Please Mark my post as best answer if that helps you!
Thanks!