Skip to main content
Skip table of contents

Automatic Folder Creation

You can automatically create a set of folders each time a parent object record is created.

This can be done via a trigger as shown below, or using Flows, which is documented in the Admin Guide.

We will use Account and cg_AccountFile_c object for our example. Each time an Account is created, S-Drive folders will be created for that Account.

  1. For the object you have, create an Apex Trigger.

  2. If you want this folder creation to take place after you create a new record, the trigger should work with an "after insert" statement.

  3. In the Apex Trigger, paste the following lines:

    trigger AccountFoldersTrigger on Account (after insert) {
    List<cg__AccountFile__c> folders = new List<cg__AccountFile__c>();
    for(Account c :{
      cg__AccountFile__c folder = new cg__AccountFile__c();
      folder.cg__WIP__c = false;
      folder.cg__Content_Type__c = 'Folder';
      folder.cg__File_Size_in_Bytes__c = 0;
      folder.cg__File_Name__c = 'Test Folder 1';
      folder.cg__Description__c = 'Some description for folder'; //use
      a description field if needed.
      folder.cg__Account__c = c.Id;
      cg__AccountFile__c folder2 = new cg__AccountFile__c();
      folder2.cg__WIP__c = false;
      folder2.cg__Content_Type__c = 'Folder';
      folder2.cg__File_Size_in_Bytes__c = 0;
      folder2.cg__File_Name__c = 'Test Folder 2'; //use name as
      folder2.cg__Description__c = 'Some description for folder'; //use a
      description field if needed.
      folder2.cg__Account__c = c.Id;
      if(folders.size() > 0){
      insert folders;
  4. Add up to your requirement the number of folders created.

  5. Change the Folder Names by changing the “File Name” section.
    For our example, the field is written as “cg__File_Name__c”.

  6. You can add descriptions to your folders by changing the “Description” field.
    For our example, the field is written as “cg__Description__c”.

  7. Make sure your Apex Trigger is active.

  8. Test by inserting a new test record and you can use these folders according to your needs

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.