Integrating Salesforce Files: A Guide to Internal and External Links
Managing Salesforce files is more tricky than it seems, even for experienced developers and admins. Yet, the skill is vital for navigating the Salesforce ecosystem and using its capabilities to the fullest extent.
In this post, experts from Synebo, a licensed Salesforce development agency delve deeper into integrating Salesforce files with internal and external links. This elaborates on our past blog about the basics of Salesforce files. It is assumed that you are familiar with the basic architecture of SF Files, the basic objects, and their relationships.
From this post, you’ll discover technical aspects of internal and public link generation, as well as discover security and compliance aspects related to handling Salesforce files.
Salesforce Internal Link Generation
Among the most used internal links in Salesforce are preview and download links. They can be used in various ways: in custom UI components to embed links for quick file previews or downloads, in hyperlink formula fields to create clickable URLs to navigate to related records or files, in email templates to direct recipients to specific Salesforce records or files, and in reports and dashboards to provide easy access to detailed records. These links enhance navigation, efficiency, and user experience within Salesforce.
Let’s get to know how to create custom preview and download links and when to use different link conditions:
Crafting Custom Preview Links
A preview link can be created using the following template:
/sfc/servlet.shepherd/version/renditionDownload?rendition=<rendition>&versionId=<version>
<version> — should be replaced by the Id of the specific ContentVersion
<rendition> –- more tricky and unfortunately not very well-documented url parameter.
Research and experiments have shown that the available options for this parameter can be as follows:
- SVGZ. Previewing for the compressed SVG files, which is a vector graphic image file extension that contains scalable images.
- THUMB120BY90. Thumbnail preview with image resolution 120 x 90
- THUMB240BY180. Thumbnail preview with image resolution 240 x 180
- THUMB720BY480. Thumbnail preview with image resolution 720 x 480
- ORIGINAL_<File_Extension>. <File_Extension> should be replaced by the file extension. Previewing a file in its original resolution.
Obviously, a preview link may not be generated for all file types, but only for those that the Salesforce platform can show. In case the platform fails to generate a preview of any file – the generated link will open a blank page or give an error as shown below.
top.location=’https://<DomainName>.my.salesforce.com/ex/errorduringprocessing.jsp
You may be additionally interested in exploring how to create data extensions in Salesforce.
Why Different Preview Link Renditions Might Be Needed
Different preview link renditions are useful for various scenarios to ensure that the content is displayed appropriately based on the context. Here are some examples of use cases for each type of rendition mentioned:
#1 SVGZ
- Use Case: Displaying vector graphics in reports or dashboards where scalability without loss of quality is crucial.
- Example: A custom UI component displaying company logos or detailed diagrams that need to maintain high resolution at any size.
#2 THUMB120BY90
- Use Case: Providing a quick, low-resolution preview of files in a list or gallery view.
- Example: Showing small thumbnails of uploaded images or documents in a custom file manager within Salesforce, helping users quickly identify the content without loading full-sized images.
#3 THUMB240BY180
- Use Case: Offering a slightly larger preview that provides more detail than the smallest thumbnail.
- Example: Displaying previews in a grid layout where users need to see more detail than the smallest thumbnail but still prioritize quick loading times.
#4 THUMB720BY480
- Use Case: Displaying a high-resolution preview for detailed examination without downloading the full file.
- Example: Showing previews of high-quality images or detailed documents where users need to view the content in more detail, such as in a custom document library.
#5 ORIGINAL_<File_Extension>
- Use Case: Allowing users to view the file in its original resolution and format.
- Example: Providing a full-sized preview for presentations, PDFs, or images where original quality is essential, such as marketing materials or detailed reports.
By offering different renditions, you can optimize the user experience based on the specific needs of each use case, ensuring that previews are both functional and efficient.
Strategies for Efficient Download Links
A download link can be created using the following templates:
#1 Version template
/sfc/servlet.shepherd/version/download/<version>
<version> — should be replaced by the Id of the specific ContentVersion
Use case: When you need to provide access to a specific version of a file.
Example: Allowing users to download the latest version of a product brochure or a specific version of a contract.
Potential pitfall: Ensure the ContentVersion ID used is correct and accessible to the user.
#2 Document template
/sfc/servlet.shepherd/document/download/<document>
<document> — should be replaced by the Id of the specific ContentDocument
Both of the link templates shown above provide the option to download a file.
The following link template gives us the ability to download multiple files as a single ZIP archive.
/sfc/servlet.shepherd/version/download/<version1>/<version2>…
<version> parameters should be replaced by the Ids of the specific ContentVersions. Can be added numerous of ids separated by “/”.
Use case: When you want to provide access to the most recent version of a document regardless of versioning.
Example: Providing a link to download the most recent company policy document.
Potential pitfall: The ContentDocument ID must be correct and users must have access to the document. If there are multiple versions, ensure users understand they are getting the latest one.
Looking for Salesforce consulting services? Let the Synebo team assist you with our diverse expertise and experience.
Expanding External Public Link Capabilities
In this part of the article, we will look at ways to get a public link to a file. This way, you can use the file link without logging into Salesforce.
Generating Public Links via Salesforce UI
From the UI perspective, it can be done using the “Share” button on the specific file.
Here’s the procedure:
#1 Open File Sharing Settings:
- Click on the file you want to share.
- A Salesforce settings window will open.
#2 Access Link Options:
- Click on the “Who can access” option.
- Additional settings will appear, including the “CREATE PUBLIC LINK” section.
#3 Set Expiration Date and Password:
- You can set an expiration date for the public link.
- You can also set a password to add an extra layer of security.
#4 Create or Copy the Link:
- If a public link was previously created, the field will be filled in. You can simply copy and use it.
- If no link exists, the field will be empty. Click on the “Create Link” button to generate a new one.
#5 Confirm Creation:
- A warning modal will appear, informing you that the link will allow anyone to access the file.
- Confirm to create the link.
Here are the implications of each setting when creating a public link
- Expiration date. Limits the duration the file is accessible via the public link. Ensures temporary access, reducing the risk of unauthorized long-term access.
- Password protection. Adds an additional layer of security by requiring a password to access the file. Enhances security, especially useful for sensitive documents.
- Pre-existing public link. Indicates that a public link has already been created, allowing for easy reuse. Prevents the creation of multiple public links for the same file, simplifying link management.
- Creating a new public link. Allows the generation of a new public link if none exists. Provides flexibility to share the file with new recipients or contexts.
That’s it about creating a public link in the UI. But the more interesting question is what the Salesforce platform handles for us, and what is going on under the hood in the described process. In a nutshell, the Salesforce platform creates an instance of a ContentDistribution object. We’ll look at this object in more detail in the next parts of this article.
Looking for Salesforce integration services or Salesforce implementation services? The Synebo team is ready, willing, and able to assist you.
The Role of the ContentDistribution Object
In this part of the article, we will talk about the ContentDistribution object as the main object that is responsible for handling public links. In the previous paragraph we described how to create a public link from the UI without any code, now let’s dive deeper into the programmatic manipulation of it. So, let’s start from relations.
When you create a ContentDistribution object, you must populate references to specific ContenDocument and ContentVersion objects by filling in the ContentDocumentId and ContentVersionId fields. In addition, you can link the created record to an Account, Campaign, or Case using the RelatedRecordId polymorphic field.
Key Fields
- ContentDocumentId: This field references the ContentDocument object and links the ContentDistribution to a specific document.
- ContentVersionId: This field references the ContentVersion object and links the ContentDistribution to a specific version of the document.
- RelatedRecordId: This polymorphic field can link the ContentDistribution object to an Account, Campaign, Case, or other standard/custom objects.
It’s essential to keep a few things in mind.
You can set several additional properties when creating a ContentDistribution object:
- Password
- ExpiryDate
The following preferences have a default value of true:
- PreferencesAllowPDFDownload
- PreferencesAllowOriginalDownload
- PreferencesNotifyOnVisit
- PreferencesLinkLatestVersion
- PreferencesAllowViewInBrowser
The whole list of available preferences can be found in the Documentation.
Therefore, from my point of view, it is better to manage it explicitly.
- At least one of the preferences must be set for the created ContentDistribution, or you will fail with an error: “MISSING_ARGUMENT, You must specify at least one delivery option.: []”
Here is a sample code for creating a ContentDistribution record:
ContentDocument contentDocument = [SELECT LatestPublishedVersionId
FROM ContentDocument
WHERE Title = 'Content for delivery'
LIMIT 1];
ContentDistribution contentDistribution = new ContentDistribution(
Name = 'Test content delivery',
ContentVersionId = contentDocument.LatestPublishedVersionId,
PreferencesAllowViewInBrowser = true,
PreferencesAllowOriginalDownload = true,
PreferencesAllowPDFDownload = false,
PreferencesNotifyOnVisit = false
);
Database.insert(contentDistribution);
Automated Management of Public Links
That’s pretty much it. Once you have created a ContentDistribution record with the required delivery parameters, you can query it for the generated urls:
ContentDistribution contentDistribution = [
SELECT DistributionPublicUrl,
ContentDownloadUrl
FROM ContentDistribution
WHERE Name = 'Test content delivery'
LIMIT 1
];
The result DistributionPublicUrl will looks like shown on screen bellow:
Notice that the Download option appears in the top panel. This is due to the PreferencesAllowOriginalDownload flag, which we set to true.
To summarize the above, once the ContentDistribution object is created, the Salesforce platform, depending on the parameters you set, will generate 3 public links that you can query and use:
- DistributionPublicUrl – main URL of the link to the shared document.
- ContentDownloadUrl – the link for downloading the file.
- PdfDownloadUrl – the link for downloading the file as a PDF.
Salesforce files functionality is utilized fairly often. For example, in one of our past cases, the Synebo team helped with help center development and integration, we used this functionality.
Security and Compliance Considerations
Now, let’s get to know better aspects related to security and compliance of file sharing in Salesforce.
Security Best Practices for File Sharing
When sharing Salesforce files, it’s crucial to follow best practices tailored to the needs of your business environment.
#1 Small Business:
- Limit access: Use role-based permissions to restrict access to Salesforce files only to those who need them.
- Enable MFA: Multi-factor authentication adds an extra layer of security to user accounts accessing Salesforce documents.
- Use audit trails: Monitor and log file access and sharing activities using Salesforce’s audit trail feature to track Salesforce file sharing.
Implementing these practices helps ensure that Salesforce file management remains secure and efficient in a small business setting.
#2 Enterprise:
- Data Encryption: Encrypt files in Salesforce both at rest and in transit to protect sensitive information.
- Advanced permissions: Implement fine-grained salesforce file sharing settings to control access at a detailed level.
- Regular audits: Conduct periodic security reviews and audits to ensure compliance and identify potential vulnerabilities in Salesforce file management.
By adopting these advanced practices, enterprises can significantly enhance the security of their Salesforce documents and mitigate risks.
Compliance and Salesforce Files
Managing Salesforce files requires adherence to various compliance regulations to protect sensitive information.
GDPR
- Data Protection Impact Assessments (DPIAs): Conduct DPIAs for data processing activities involving Salesforce files to assess and mitigate risks.
- Right to access and уrasure: Ensure that mechanisms are in place to quickly respond to data subject requests regarding their Salesforce documents.
Ensuring GDPR compliance for Salesforce files helps protect user data and avoid hefty fines.
HIPAA
- Data Security: Implement administrative, physical, and technical safeguards for Salesforce files containing PHI (Protected Health Information).
- Breach Notification: Have protocols for detecting and reporting breaches involving Salesforce file links.
Meeting HIPAA requirements is crucial for maintaining the confidentiality and integrity of healthcare-related Salesforce files.
Tools and features for ensuring сompliance
- Salesforce Shield: Provides encryption, monitoring, and auditing tools to help maintain compliance with various regulations.
- Field Audit Trail: Enables tracking changes to ContentDistribution object Salesforce, ensuring detailed historical records for compliance purposes.
- Einstein Data Detect: Helps identify and protect sensitive data within Salesforce files integration to comply with regulations like GDPR and HIPAA.
Utilizing these tools ensures that Salesforce file management meets the necessary compliance standards effectively.
Looking for Salesforce development services from a licensed provider? The Synebo team must be your primary choice!
Final Take
Mastering Salesforce Files integration is essential for leveraging the platform’s full potential. This guide has covered the intricacies of generating internal and external links, emphasizing security and compliance. Whether crafting custom preview links or managing public access, understanding these technical aspects can significantly enhance file management in Salesforce. By following best practices and utilizing available tools, you can ensure secure and efficient file sharing, tailored to your business needs.
Consider Synebo as your trusted Salesforce partner. We are a licensed provider, with more than 8 years of experience delivering Salesforce-based software solutions, integration, and more. Our team is widely recognized as experts.
Contact Synebo to request Salesforce services for your project