Newer Version Available
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
- Salesforce CRM Content must be enabled to query shared documents. To query content deliveries, content deliveries must be enabled.
- Users (including users with the “View All Data” permission) can query only the files that they have access to. If the file is managed by a Content Library, the user must have “Deliver Content” enabled in the library permission definition and be a member of the library. If the file isn’t managed by a Content Library, the user must have the “Enable Creation of Content Deliveries for Salesforce Files” permission.
- Users can query the DistributionPublicUrl and Password fields only if they are the file owner, if the file is shared with them, or if the RelatedRecordId specifies a record that the users can access.
- If the shared document is deleted, the delete cascades to any associated ContentDistribution. The ContentDistribution is still queryable by using the QueryAll verb.
- If the shared document is archived, the only fields that users can edit are ExpiryDate and PreferencesExpires.
- Customer Portal users can’t access this object.
- Chatter Free users can’t access this object.
Fields
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.
This trigger
for the ContentDistribution object enforces the delivery policy rules for each
file:
The trigger calls this helper
class:1trigger deliveryPolicy on ContentDistribution (before insert) {
2 for (ContentDistribution cd : trigger.new) {
3 String versionId = DeliveryPolicyHelper.getContentVersionId(cd);
4 ContentVersion version = [select DeliveryPolicy__c from ContentVersion where Id = :versionId];
5 String policy = version.DeliveryPolicy__c;
6 if (policy.equals('Blocked')) {
7 cd.addError('This file is not allowed to be delivered.');
8 } else if (policy.equals('Password required')){
9 if (!DeliveryPolicyHelper.requirePassword(cd)) {
10 cd.addError('To deliver this file, set a password.');
11 }
12 }
13 }
14}1public class DeliveryPolicyHelper {
2 public static String getContentVersionId(ContentDistribution cd) {
3 if (cd.ContentVersionId != null) {
4 return cd.ContentVersionId;
5 } else {
6 String versionId = [select LatestPublishedVersionId from ContentDocument where Id = :cd.ContentDocumentId].get(0).LatestPublishedVersionId;
7 return versionId;
8 }
9 }
10
11 public static boolean requirePassword(ContentDistribution cd) {
12 return cd.PreferencesPasswordRequired;
13 }
14}