Create Bulk Containers From Salesforce
The T4S managed package class “fuseit_t4s.TrimConnector
" has several public methods to code against, and use T4S directly within code.
The Create Bulk Trim Records and Create Bulk Containers are asynchronous methods that require the T4S Settings for the sObject type configured, so any metadata used in the creation can be queried and used during the bulk process.
The results for the Create Bulk Containers are saved back into Salesforce as T4S “fuseit_t4s__Trim_Settings_Container__c“ records.
Each “fuseit_t4s__Trim_Settings_Container__c“ holds the unique mapping between the Salesforce sObject and the CM Container URI.
The results for the bulk Trim Records creation are saved back into Salesforce as T4S “fuseit_t4s__Trim_Record__c“ records.
Each “fuseit_t4s__Trim_Record__c“ holds the unique mapping between the ContentDocument/ContentDocumentVersion or Attachment sObject and the CM Record.
Below is an example of Bulk Create Containers, where existing Cases of a certain Salesforce RecordType, that do not yet have their own mapped Container, will have a new Container created.
//Select Cases that meet the criteria or maybe use your own sObject After Insert trigger.
Map<Id,Case> mapCases = new Map<Id,Case>([
Select Id, CreatedDate, CaseNumber, RecordTypeId, Origin from Case
Where
Origin = 'Web' And
CreatedDate > 2023-01-26T23:55:02.000Z And
CreatedDate < 2023-02-07T01:01:02.000Z And
RecordTypeId = '<SomeRecordTypeId>'
Order By CreatedDate]
);
//Try and find any existing Container mapping for the selected Cases.
List<fuseit_t4s__Trim_Settings_Container__c> containers = [Select Id, CreatedDate, Name, fuseit_t4s__sObject_ID__c from fuseit_t4s__Trim_Settings_Container__c Where fuseit_t4s__sObject_ID__c in: mapCases.keySet()];
//Remove those existing mapped Cases
if(containers.size() > 0) {
for(fuseit_t4s__Trim_Settings_Container__c con : containers) {
System.Debug('Removing Id ' + con.fuseit_t4s__sObject_ID__c);
mapCases.remove(con.fuseit_t4s__sObject_ID__c);
}
}
String prefix = '500'; //Case
fuseit_t4s__Trim_Setting__c setting = [Select Id, Name, fuseit_t4s__Trim_Server__c
From fuseit_t4s__Trim_Setting__c
Where
fuseit_t4s__Auto_Create_Sub_Container__c = true And
fuseit_t4s__sObject_Prefix__c =: prefix WITH SECURITY_ENFORCED limit 1];
fuseit_t4s.TrimConnector.createBulkContainers(mapCases.values(), setting.Id);
If you wish to use the saved CM Container metadata within the “fuseit_t4s__Trim_Settings_Container__c“ when they are created, you can create your own after inert or update trigger.
e.g.
/*****************************
* Class : TrimContainerTrigger
* Created By :
-----------------------------------------------------------------------------------
* @description : After a new T4S Trim Container has been created in TRIM, and Salesforce updated with
* the new fuseit_t4s__Trim_Settings_Container__c record, the AfterContainerInsert method is called.
-----------------------------------------------------------------------------------
* Version History:
* Date Developer Name Detail Features
*
****************************/
trigger TrimContainerTrigger on fuseit_t4s__Trim_Settings_Container__c (after insert, after update) {
if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)) {
YourClassHelper.afterInsertUpdate(Trigger.New);
}
}