Public Link Generation Using Trigger

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Content Version Trigger to call apex class

-
-
-
trigger contentVersionExternalLink on ContentVersion (after insert) {
ContentTriggerHandler.createPublicLink(trigger.new);
}

Create ContentDocumentLinktrigger to make visible to all User


-
-
-
trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert)
{
for(contentDocumentLink l :Trigger.new)
{
l.visibility='AllUsers';
}
}

Create a class to generate Public links for files

-
-
-
-

public class ContentTriggerHandler


{
public static void createPublicLink(list<contentVersion> contentVer)
{
system.debug(contentVer);
ContentDistribution [] distributionui=new List<ContentDistribution>();
for(contentVersion c:contentVer)
{
distributionui.add(createContentDistribution(c.Id));
}
insert distributionui;
system.debug(distributionui[0].DistributionPublicUrl);
}
public static ContentDistribution createContentDistribution(Id conId)
{
ContentDistribution dc=new ContentDistribution();
dc.ContentVersionId=conId;
dc.Name='External Link';
dc.PreferencesAllowOriginalDownload=true;
dc.PreferencesAllowViewInBrowser=true;
dc.PreferencesNotifyOnVisit=false;
system.debug(dc);
return dc;
}
}

You might also like