Vlocity Facts #26 || Can we display files with out using LWC and file related list?

 Yes we can display the files with out using LWC but we need to write triggers and we can display with the help off Flexcard.

When we upload a file it will create 3 records.

Content Version -- where the version of the file stores.
ContentDocument is the parent object of ContentDocumentId, ContentVersion where it can store the versions of the file.
ContentDocumentLink -- It will be the link between the Parent object [LinkedEntityId] and the ContentDocument object

To achieve our task we need to have the link of the file and it is should be download url.

ContentDistribution Object
Represents information about sharing a document externally. 

First when ever a ContentDocumentLink record is created we need to make the record Visible to all users.

trigger MakeFileVisible on ContentDocumentLink (before insert) {
for(ContentDocumentLink l:Trigger.new) {
       l.Visibility='AllUsers';
}
}

and after the ContentDocumentLink is created we can create the ContentDistribution record.

trigger CreateDistribution on ContentDocumentLink (after insert) {
Set<Id> CId = new Set<Id>();
list<ContentDistribution> lstCD = new list<ContentDistribution>();
for(ContentDocumentLink Link : Trigger.new)
{
    CId.add(Link.ContentDocumentId); 
}
if(!CId.isEmpty())
{
   List<ContentVersion> file = new List<ContentVersion>([SELECT Id, Title,ContentDocumentId FROM ContentVersion WHERE ContentDocumentId IN :CId]);
 for(ContentVersion CV: file)
{

ContentDistribution CD = new ContentDistribution();
         CD.Name = CV.Title;
         CD.ContentVersionId = CV.Id;
        CD.PreferencesAllowViewInBrowser = true;
       lstCD.add(CD);
}

 insert lstCD;
} }

After this we need to create Dataraptor to extract the content distribution link

Image
In output tab from extract json path select the DistributionPublicUrl and Name map with output json path

Use this DataRaptor as a data source to the flexcard and use data table element to display the link and the name of the document.

This process is used when you are uploading a file to the standard file relatedlist.

If you fileupload element in flow or in Omnistudio with out apex triggers we can create ContentDistribution record by using dataraptors or create record element in flow.

Note: The above mentioned code is not written according to salesforce best practice. Just for basic understanding use the code.


Comments

Popular posts from this blog

Vlocity Facts #01 | OmniStudio DataRaptors

Vlocity Facts #34 || Getting the details from the URL in a FlexCard and an Omniscript

Vlocity Facts #44 || Communication between Omniscript and Flexcard [Pub/Sub]