ContentDistribution

Represents information about sharing a document externally. This object is available in API version 32.0 and later.

Supported Calls

create()delete()describeSObjects()query()retrieve()undelete()update()upsert()

Special Access Rules

Fields

Field Name Details
ContentDocumentId
Type
reference
Properties
Filter, Group, Nillable, Sort
Description
ID of the shared document.
ContentDownloadUrl
Type
string
Properties
, SortNillable
Description
The link for downloading the file. This field is available in API version 40.0 and later.
ContentVersionId
Type
reference
Properties
Create, Filter, Group, Sort
Description
ID of the shared document version.
DistributionPublicUrl
Type
string
Properties
Nillable, Sort
Description
URL of the link to the shared document.
ExpiryDate
Type
dateTime
Properties
Create, Filter, Nillable, Sort, Update
Description
Date when the shared document becomes inaccessible.
FirstViewDate
Type
dateTime
Properties
Filter, Nillable, Sort
Description
Date when the shared document is first viewed.
LastViewDate
Type
dateTime
Properties
Filter, Nillable, Sort
Description
Date when the shared document was last viewed.
Name
Type
string
Properties
Create, Filter, Group, Sort, Update
Description
Name of the content delivery.
OwnerId
Type
reference
Properties
Create, Filter, Group, Sort, Update
Description
ID of the user who owns the shared document.
PdfDownloadUrl
Type
string
Properties
, SortNillable
Description
The link for downloading the file as a PDF. This field is available in API version 40.0 and later.
Password
Type
string
Properties
Group, Nillable, Sort
Description
A password that allows access to a shared document.
PreferencesAllowOriginalDownload
Type
boolean
Properties
Create, Filter, Update
Description
When true, the shared document can be downloaded as the file type that it was uploaded as.

When false, download availability depends on whether a preview of the file exists. If a preview exists, the file can’t be downloaded. If a preview doesn’t exist, the file can still be downloaded.

If the shared document is a link, it can’t be downloaded.

PreferencesAllowPDFDownload
Type
boolean
Properties
Create, Filter, Update
Description
When true, the shared document can be downloaded as a PDF if the original file type is PDF or if a PDF preview has been generated.
PreferencesAllowViewInBrowser
Type
boolean
Properties
Create, Filter, Update
Description
When true, a preview of the shared document can be viewed in a Web browser.
PreferencesExpires
Type
boolean
Properties
Create, Filter, Update
Description
When true, access to the shared document expires on the date that’s specified by ExpiryDate.
PreferencesLinkLatestVersion
Type
boolean
Properties
Create, Filter, Update
Description
When true, users see the most recent version of a shared document. When false, users see the version of the document that’s shared, even if it isn’t the most recent version.
PreferencesNotifyOnVisit
Type
boolean
Properties
Create, Filter, Update
Description
When true, the owner of the shared document is emailed the first time that someone views or downloads the shared document.
PreferencesNotifyRndtnComplete
Type
boolean
Properties
Create, Filter, Update
Description
When true, the owner of the shared document is emailed when renditions of the shared document that can be previewed in a Web browser are generated.
PreferencesPasswordRequired
Type
boolean
Properties
Create, Filter, Update
Description
When true, a password, specified by Password, is required to access the shared document.
RelatedRecordId
Type
reference
Properties
Create, Filter, Group, Nillable, Sort, Update
Description
ID of the record, such as an Account, Campaign, or Case, that the shared document is related to.
ViewCount
Type
int
Properties
Filter, Group, Nillable, Sort
Description
The number of times that the shared document has been viewed.

Usage

Use this object to create, update, delete, or query information about a document shared externally via a link or via Salesforce CRM Content delivery.

The ContentDistribution object supports triggers before and after these operations: insert, update, delete. It supports triggers after undelete.

Example

The VP of Marketing wants file authors to specify whether their files can be shared with external people using content delivery. He also wants some files to have a password. You can add a custom field DeliveryPolicy on the ContentVersion object. Make the custom field a picklist with the values, Allowed, Blocked, and Password required. Add the field to the ContentVersion layout so that the user can set the delivery policy per file. Then, add an insert trigger for the ContentDistribution object to enforce the rules based on the delivery policy set in the file.
Note

Note

The ContentVersionId for ContentDistribution must be unique.

This trigger for the ContentDistribution object enforces the delivery policy rules for each file:
trigger deliveryPolicy on ContentDistribution (before insert) {
    for (ContentDistribution cd : trigger.new) {
        String versionId = DeliveryPolicyHelper.getContentVersionId(cd);
        ContentVersion version = [select DeliveryPolicy__c from ContentVersion where Id = :versionId];
        String policy = version.DeliveryPolicy__c;
        if (policy.equals('Blocked')) {
            cd.addError('This file is not allowed to be delivered.');
        } else if (policy.equals('Password required')){
            if (!DeliveryPolicyHelper.requirePassword(cd)) {
                cd.addError('To deliver this file, set a password.');
            }
        } 
    }
}
The trigger calls this helper class:
public class DeliveryPolicyHelper {
    public static String getContentVersionId(ContentDistribution cd) {
        if (cd.ContentVersionId != null) {
            return cd.ContentVersionId;
        } else {
            String versionId = [select LatestPublishedVersionId from ContentDocument where Id = :cd.ContentDocumentId].get(0).LatestPublishedVersionId;
            return versionId;
        }
    }
    
    public static boolean requirePassword(ContentDistribution cd) {
        return cd.PreferencesPasswordRequired;
    }
}
Important

Important

Apex has a per organization limit of 10 concurrent requests that last longer than 5 seconds. A trigger that uploads files can easily hit this limit.