You are here:
Save Generated Documents to a Default Library
Create a trigger to save all generated documents to the Vlocity Document Template Library and provide library access to a user.
| REQUIRED EDITIONS AND USER PERMISSIONS |
|---|
| Available in: Lightning Experience |
| Available with Vlocity Contract Lifecycle Management: Enterprise, Performance, and Unlimited editions. |
| USER PERMISSIONS NEEDED | |
|---|---|
| To provide users access to the Vlocity Document Template Library. | ContractMgmtInd HINS Admin User OR ContractMgmtInd CME Admin User |
-
Create a trigger to save generated documents to the Vlocity Document Template Library.
Users who have access to the library can view all the generated documents.
- In your Salesforce org, from Setup, select Object Manager.
- Enter Document Element in the Quick Find box, then select Contract Document Element.
- Click .
-
Paste the sample trigger.
trigger ContractDocumentCollection on vlocity_cmt__ContractDocumentCollection__c (after Insert) { Set<Id> contentVersionIdsInserted; if (Trigger.isInsert) { contentVersionIdsInserted = new Set<Id> (); for(SObject so: Trigger.new) { vlocity_cmt__ContractDocumentCollection__c docCollection = (vlocity_cmt__ContractDocumentCollection__c)so; if(docCollection.vlocity_cmt__ContentVersionId__c != null) { contentVersionIdsInserted.add(docCollection.vlocity_cmt__ContentVersionId__c); } } Id workspaceId = [ SELECT Id, Name FROM ContentWorkspace WHERE Name = 'Vlocity Document Template Library' LIMIT 1].Id; List<ContentDocumentLink> contentDocumentLinks = new List<ContentDocumentLink>(); List<ContentVersion> contentVersions = [SELECT ContentDocumentId FROM ContentVersion where Id IN :contentVersionIdsInserted]; for(ContentVersion contentVersion: contentVersions) { ContentDocumentLink documentLink = new ContentDocumentLink(ContentDocumentId=contentVersion.ContentDocumentId, LinkedEntityId=workspaceId, ShareType='I', Visibility='AllUsers'); contentDocumentLinks.add(documentLink); } Insert contentDocumentLinks; } } - Save your changes.
- From the App Launcher, find and select Files.
- Click .
- For Add Members, select People.
- Enter the name of the user in the search field.
- For access, select Viewer, Library Administrator, or Author.
- Click Add.

