The Ultimate Guide to File Upload & Content Distribution in Salesforce

Introduction

Uploading files to Salesforce is a common requirement, but ensuring they are appropriately distributed for public or internal access can be challenging. Salesforce Content Distribution allows us to generate public links for files stored in Salesforce Content.

This blog will guide you through the convenient process of automatically uploading files with a Lightning Web Component (LWC) and creating Content Distribution records. This process allows us to generate shareable links, which help render materials inside or outside Salesforce or include images when creating PDF documents.

Step 1: Uploading Files Using LWC

Salesforce provides the lightning-file-upload component, which allows users to upload files and associate them with a record.

LWC Component for File Upload

This component enables users to upload files and calls Apex to process them.

LWC HTML (fileUploadComponent.html)

LWC HTML

LWC JavaScript (fileUploadComponent.js)

LWC JavaScript

How This Works

  1. Users upload files using lightning-file-upload.
  2. The handleUploadFinished method retrieves the uploaded file’s documentId.
  3. The createContentDistribution Apex method generates a public link for the uploaded file.

 

Step 2: Creating Content Distribution in Apex

Once a file is uploaded, we must generate a public link using Content Distribution.

Apex Controller (ContentDistributionHandler.cls)

Screenshot 3 - Apex

Step 3: Verifying the Implementation

Once a file is uploaded:

  1. The lightning-file-upload component uploads it to Salesforce Files (ContentVersion).
  2. The Apex method creates a ContentDistribution record for the file.

The public link can be retrieved from the DistributionPublicUrl field.

Conclusion

This implementation provides a seamless experience for users to Upload files via LWC and access the ContentDistribution records for public sharing or downloading.

  1. By automating the creation of ContentDistribution records, this process saves time and effort. It also ensures that public URLs are generated for easy file-sharing, enhancing the user experience.
  2. Generate public URLs for easy file-sharing.

Key Benefits

  • Automation: No manual sharing is required.
  • With this process, access to public URLs can be controlled via preferences, ensuring the security of the shared files.
  • Efficiency: LWC handles file uploads asynchronously, allowing you to focus on other tasks while the system works in the background.

This approach is perfect for applications requiring file sharing, document management, or public downloads.

ContentDistribution Blog

Public URL being displayed after successful image upload

Authors: Gella Sangamesh Gupta

Leave a Comment

Your email address will not be published. Required fields are marked *

Recent Posts

The Ultimate Guide to File Upload & Content Distribution in Salesforce
The Ultimate Guide to File Upload & Content Distribution in Salesforce
SERVICE AGENT WITH CONTEXT VARIABLE
Agentforce Service Agent With Context Variable
Implementing Data Tables in Salesforce Screen Flow- A Comprehensive Guide
Implementing Data Tables in Salesforce Screen Flow: A Comprehensive Guide
Field Service Operations with ServiceMax Work Order Management
Field Service Operations with ServiceMax Work Order Management
High Charts In Salesforce
Highcharts In Salesforce - Highcharts 3D
Document

How can i help you? close button

powered     by   ABSYZ
Scroll to Top