Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
ContentDistribution
Supported Calls
create(), delete(), describeSObjects(), query(), retrieve(), undelete(), update(), upsert()
Special Access Rules
- Content deliveries must be enabled to query content deliveries.
- 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.
- Guest users of Experience Cloud sites can't access or create 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
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}