AFC for Custom sObjects
Custom Salesforce objects require both admin configuration and developer enablement to use Auto Folder Creation (AFC). Admins define the AFC folder hierarchy and optional enhancements (categories, translations, related folders). Developers must create and deploy an Apex trigger that calls Cartularius AFC entry points for create/rename/delete operations.
When to use this
Use this page when:
- You want to automate the AFC folder hierarchy for a custom object.
- You are preparing a sandbox-to-production deployment plan that includes both config and code.
- You need a single canonical checklist for developers + admins.
Prerequisites
- Ability to modify Setup metadata (Global Value Set / Picklist Value Set).
- Ability to deploy Apex triggers.
- Admin ownership of AFC configuration rules.
How it works in Cartularius
Custom objects need two enablement layers:
Ensure AFC runs at record lifecycle events
Developers add an after insert / after update / after delete trigger that calls Cartularius AFC entrypoints:
GlobalDocumentManager.autoFolderCreation(Trigger.new)GlobalDocumentManager.renameRecords(Trigger.new, Trigger.oldMap)GlobalDocumentManager.sfRecordDeletion(Trigger.old)
Make the custom object available for AFC configuration
Admins (or release engineers) add the object API name (including __c) to the CDM SObjects Global Value Set so the object becomes selectable when configuring AFC.
Implementation / Configuration steps
Step 1: Deploy the custom object trigger
Use the following trigger pattern. Replace names in brackets with your object/trigger names.
trigger [CustomObjectTrigger] on [CustomObject__c] (after insert, after update, after delete) {
if (Trigger.isInsert) {
try {
GlobalDocumentManager.autoFolderCreation(Trigger.new);
} catch (Exception e) {
for (SObject newRecord : Trigger.new) {
newRecord.addError('Cartularius AFC folder creation failed: ' + e.getMessage());
}
}
}
if (Trigger.isUpdate) {
try {
GlobalDocumentManager.renameRecords(Trigger.new, Trigger.oldMap);
} catch (Exception e) {
for (SObject updatedRecord : Trigger.new) {
updatedRecord.addError('Cartularius AFC folder rename failed: ' + e.getMessage());
}
}
}
if (Trigger.isDelete) {
try {
GlobalDocumentManager.sfRecordDeletion(Trigger.old);
} catch (Exception e) {
for (SObject oldRecord : Trigger.old) {
oldRecord.addError('Cartularius AFC deletion maintenance failed: ' + e.getMessage());
}
}
}
}Step 2: Add a new entry to the CDM SObjects Global Value Set
- In Setup, open Picklist Value Sets.
- Open the CDM SObjects Global Value Set.
- Add the custom object API name(s), including
__c. - Save.
Step 3: Validate results
After deploying the trigger and completing the required admin configuration, validate end-to-end AFC behavior in the target environment.
