Back

How to Work With Salesforce Files: The Basics

How-to Guides and Tutorials
14 min
Working with salesforce files: the basics

Getting started with Salesforce can be complex since the ecosystem and capabilities it provides have advanced over the years. One of the primary components Salesforce devs, admins, and architectures work with are files. They are features that allow users to store, manage, and share files within the Salesforce platform

In this post, Synebo engineers, with all our diverse experience and vast expertise, will shed light on Salesforce files, their types, Salesforce attachments vs files differences, architecture, and sharings of Salesforce files. We’ll also delve you into front-end and back-end perspectives on Salesforce files, notes, and attachments.

What Are Salesforce Files?

Salesforce files provide a centralized, cloud-based solution for storing and accessing various types of documents and multimedia files. Files in Salesforce are integrated throughout the Salesforce ecosystem, allowing users to attach files to specific records, collaborate on documents, and share files securely within and outside their organization.

The different aspects or types of file storage and organization within the Salesforce ecosystem are:

  1. Documents. This term generally refers to traditional file formats used in business environments, such as Word documents, PDFs, and spreadsheets. In Salesforce, these are the types of files you might store and manage using various features, including Salesforce files.
  2. Content. In Salesforce, “Content” can refer to rich media files, including videos, images, and audio files. These are the types of files that might require more storage space and bandwidth, and Salesforce provides tools to manage and share these files effectively, especially for marketing and communication purposes.
  3. Libraries. Within Salesforce, Libraries are used to organize files in a structured way. They allow users to categorize and store related files together, making it easier to manage and access them. 

Salesforce files encompasses the management over the listed. As for the main Salesforce file types categorizing in all above mentioned, they are the following:

  • Documents: Word processing files, PDFs, and text files.
  • Spreadsheets: Excel files and other spreadsheet formats.
  • Presentations: PowerPoint presentations and similar formats.
  • Images: JPEG, PNG, GIF, and other image formats.
  • Videos and audio files: Various multimedia formats.
  • Other file types: Depending on the Salesforce configuration and integrations, it can support a variety of other file types.

The main aspects associated with Salesforce files are:

  • Integration with Salesforce records: Files can be linked to specific Salesforce records, like attaching sales presentations to opportunities or manuals to product records, providing contextual relevance.
  • Collaboration and sharing: Users can collaborate on files through commenting, liking, and sharing, enhancing teamwork and communication within Salesforce.
  • Versioning: Salesforce tracks different file versions, allowing users to view and revert to older versions, ensuring data integrity and maintaining a change history.
  • Permissions and sharing settings: Access controls and permissions can be set by administrators, specifying who can view, edit, or delete such Salesforce documents, thus protecting sensitive information.
  • Chatter integration: Files integrate with Salesforce Chatter, enabling sharing in Chatter feeds and fostering a social collaboration layer.
  • Search and discovery: Robust search features allow for efficient file location using metadata, keywords, or content.
  • Salesforce connect: Enables access to files through Salesforce Connect, linking external data sources and displaying files from external systems within Salesforce.
  • Mobile accessibility: Files are accessible on mobile devices, supporting on-the-go access, viewing, and collaboration.
  • Analytics and Reporting: Salesforce offers reporting and analytics for files, tracking usage, views, and other metrics.

Salesforce files represent a modern approach to document and multimedia file management, deeply integrated into the Salesforce ecosystem to support various business processes, improve efficiency, and enhance collaboration.

Difference Between Files vs Notes and Attachments Salesforce

While files are more versatile, notes and attachments are more specific and focused on particular functionalities. Let’s take a look at the detailed comparison of files vs notes and attachments based on distinctive features they have.

Feature Salesforce Files Salesforce Notes and Attachments
Storage Model Unified storage detached from specific records. Object-specific attachments tied to individual records.
Integration Seamlessly integrates with other Salesforce features. Well-integrated, but may lack certain advanced features.
Type Support Broad support for various file types, including multimedia. Primarily supports standard document formats and some image types.
Backup and Recovery Robust backup and recovery processes, often integrated with Salesforce’s overall data management system. Backup and recovery dependent on Salesforce’s standard data backup procedures; may be less flexible.
Cross-Object Reference Easily associated with multiple objects. Tied to a specific record; duplicative effort for cross-object references.
Version Control Supports multiple versions and version history. Limited version control; lacks systematic tracking of changes.
Search Functionality Improved search capabilities with advanced metadata. Basic search functionality based on file names and details.
Collaboration Features Enables collaborative editing through Salesforce Quip. Basic collaboration; primarily focused on document association.
Preview Options Facilitates detailed organization with rich metadata. Relies on basic file details for organization.
Granular Organization Enhanced options for organizing files with rich metadata. Basic organization based on file details.
External Application Dependency Reduced dependency on external applications for file previews. Often requires external applications for file viewing.
Customization Highly customizable with additional attributes and tags. Limited customization options beyond standard fields.

It’s important to note that there’s no discussion about what Salesforce documents to use, files, or notes with attachments. They are tools that devs, architectures, and administrators use when working with Salesforce as needed. So, this comparison serves the goal of understanding both concepts better to use them in the right way. 

Are you looking for a Salesforce development provider to help you with your Salesforce solution? Reach out to Synebo and let’s discuss opportunities!

Salesforce File Management: UI, Architecture, and Development Perspectives

Now, let’s get to know Salesforce file management in several of its main aspects from the development perspective. It includes tips and how-tos helpful for all specialists working with the ecosystem. 

Salesforce Files in UI

In the Salesforce admin environment, files are displayed under the parent object realized with related list Notes & Attachments. From it, you can add a new file by clicking the “Upload Files button.”

Salesforce files admin

Alternatively, you can find all files that are accessible to you with additional categorization in the “Files tab.” The “Upload Files” button is the same as on the previous screenshot.

Files_List

After you choose the File, it will be uploaded. Then, simply press the “Done” button and the file will be successfully saved to your Salesforce org.

Uploading_File_Modal_Window (1)

Additional file properties as well as support actions are available by clicking on the uploaded file. Here you can download or share the file, get a public link to it, view file details, upload a new file version, edit details of the file, and delete it.

Files details

Architecture of Salesforce Files

Let’s proceed with the review of notes and attachments from the architecture perspective. In its basic form, the Salesforce documents data model looks like a chain of linked containers of data and its values. You can review the basic representation of the data model in the diagram below.

Data_Model

Each object from the presented diagram can be considered separately.

Basically, managing files and their relations in Salesforce are represented by three main objects, ContentVersion, ContentDocument, and ContentDocumentLink plus content data owner object. The mentioned objects appear instead of one “Attachment” object. Although the new data model is more complex, it gives us the ability to link a file with multiple records without duplicating binary data and provides greater flexibility. There is also version history that regulates object field changes.
Here are more detailed explanations to each object and version history: 

It is the main object that directly stores the binary data of the file version. It’s also one of the most used objects when you are working with files. 

In contrast to ContentDocument, this object supports the whole functionality of SObject (including insertion and adding new fields, restricted on ContentDocument). It contains most of the file version properties, file update history, etc.

It is an object that stores a reference to the latest published ContentVersion and its associated properties. 

Content document is the main object from a data model perspective. It is the basis for all subsequent file life, manipulation, and creation of subordinate objects. You cannot find this object in the Object Manager from org Setup. But you still have the option to open it from the developer console. You cannot add new fields directly to it or programmatically create a record. However, you can use other DML operations and add triggers to it.

It represents an object that links a file (ContentDocument) to a specific parent record. Additionally, provides sharing and visibility properties. Once this object is created, the corresponding file will appear in the org UI as associated with the specified parent. 

They represent the history of the ContentVersion and ContentDocument objects field changes. Both of them are read-only.

  • Content Data Owner Object. 

Content Data Owner Object represents the parent object of the file. As part of a data model based on the polymorphic LinkedEntityId field of a ContentDocumentLink object, can be an object with the type of most standard and custom objects.

Basically, a ContentDocument record can have multiple ContentVersion records associated with it. It gives us the ability to keep a version history of file data and quickly restore it to a previous state if necessary. But in the related list notes & attachments we will always see only one ContentVersion record, which is the most recent (IsLatest field is populated as true). There can be only one ContentVersion record associated with some ContentDocument in the system and marked as the most recent. This flag is filled in automatically by the platform.

Notes & Attachments From the Back-End Development Perspective

Now that we have some general knowledge about file management objects, let’s talk about how to use them in a development context. We will also review the relationship of objects and some other nuances using excerpts from programmatic file creation as example.

Programmatically file creation starts from insertion of ContentVersion record. 

The ContentDocument record will be created automatically as a part of the ContentVersion saving transaction and the corresponding ContentDocumentId will be populated on the ContentVersion record as well.

ContentVersion contentVersion = new ContentVersion(Title = 'NewFile', VersionData = Blob.valueOf('file content'), PathOnClient = 'NewFile.txt');

Database.insert(contentVersion);

In the example above, we have successfully created a new file in Salesforce. If we want to link the created file to any parent record, we need to create an instance of ContentDocumentLink. Note that after creating the ContenVersion object, we have to query its ContentDocumentId. The simple code example is shown below: 

ContentVersion contentVersion = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :contentVersion.Id LIMIT 1];

// For instance, we have to bind created file with an Account named 'Test account'

Account testAccount = [SELECT Id FROM Account WHERE Name = 'Test Account' LIMIT 1];

ContentDocumentLink contentDocumentLink = new ContentDocumentLink(

LinkedEntityId = testAccount.Id,

ContentDocumentId = contentVersion.ContentDocumentId

);

Database.insert(contentDocumentLink);

With two small code samples, we created a new file in Salesforce.org and linked it to an Account record.

When searching (querying) a particular ContentVersion record, you must remember to filter the query by the IsLatest flag. For instance, if you want to find a file named “Contract 10.docx”, the query should look like this:

List<ContentVersion> contentVersions =

[SELECT ContentDocumentId

 FROM ContentVersion

 WHERE PathOnClient = 'Agreement 10.docx'

   AND IsLatest = true];

Notes & Attachments From the Front-End Development Perspective

At the beginning of the post, we discovered where we can find the files and how we can create them. The “Upload Files” button in the standard user interface is generated by the platform and fully handles the file creation process under the hood.

Custom_Upload

if you need to add some custom button to upload files? This is where a component called lightning-file-upload lwc comes in handy. It handles file creation (inserting ContentDocument and ContentVersion) just like the standard UI and looks exactly the same:

HTML code here will be something like this:

<lightning-file-upload

            label="Attach receipt"

            name="fileUploader"

            accept={acceptedFormats}

            record-id={myRecordId}

            onuploadfinished={handleUploadFinished}

            multiple

        >

        </lightning-file-upload>

Javascript lwc side handles basic file upload operations and as a result, returns a detailed list of ContentDocuments identifiers in the onuploadfinished event.

Sharings in Salesforce Files

Let’s have a brief overview of the main features of basic object-sharing management. More detailed information can be found in the file privacy and sharing official guide.

In ContentDocument and ContentVersion, we have the same fields with picklist types which are SharingOption and SharingPrivacy:

  • SharingOption can be set to “Allowed” and “Restricted” (corresponding values “A” and “R”, default is “A”). In the UI, it is represented as a checkbox named “Prevent others from sharing and unsharing”. Controls whether the file sharing will be frozen. 
  • SharingPrivacy can be set to “Visible to Anyone With Record Access” and “Private on Records” (corresponding values “N” and “P”, default is “N”). Controls file sharing privacy.

In the ContentDocumentLink object, we have ShareType and Visibility fields relevant to the topic under discussion:

  • ShareType can be set to “Viewer,” “Collaborator” and “Inferred” (corresponding values “V”, “C” and “I”). Pay attention, this field is mandatory. Indicates the type of permission granted to the user when sharing the file.
  • Visibility can be set to “AllUsers,” “InternalUsers” and “SharedUsers”. Indicates whether the file is available to all users, internal users, or shared users.

Need a trusted Salesforce consulting firm? Contact Salesforce specialists from Synebo and let’s discuss!

Salesforce File Limits

Since all areas in Salesforce have some limitations, files are no exception. While it may not be the most fascinating subject, understanding these limitations is crucial to prevent unexpected ‘limit’ exceptions. Here’s a more detailed look into this area:

File size and sharing limits:

  • Maximum file upload size. Restricts the size of files that can be uploaded in Salesforce, varying by the method of upload (e.g., via Chatter, communities, or as attachments).
  • Sharing capacity. Governs the number of files and the extent to which they can be shared within the Salesforce environment.

General requirements for them are described in the article File Size and Sharing Limit.

Salesforce CRM Content Limits:

  • Storage capacity. Determines the total amount of data storage space available for files and CRM content.
  • File type restrictions. Specifies the types of files that are permissible within the CRM, impacting both storage and security protocols.

General requirements for them are described in the article Salesforce CRM Content Limits

Apex Governor Limits:

  • Total Heap Size. Sets the maximum memory space that Apex code can consume during execution, crucial for ensuring efficient resource usage and preventing system overloads in different contexts.

General requirements for them are described in the article Apex Governor Limits

Each of these limitations plays a vital role in ensuring the smooth operation and management of files and resources within the Salesforce ecosystem. Familiarity with them is essential to prevent system errors and optimize the platform’s use.

Navigating Salesforce File Challenges

Since the technology is a bit complex, you may face some issues when utilizing it. Let’s take a look at common files challenges and recommended ways to solve them:

Tackling VersionData Errors

Problem description: We need to update some of the existing ContentVersion fields. At the same time, we need to get the VersionData value (without any updates). 

Update DML operation failing with an error – “INVALID_STATUS, You can’t set the VersionData when IsMajorVersion is true”. 

Tips to solve it: To get around this problem, we can simply nullify this field before calling the DML update operation. And yes, it doesn’t affect the saving ContentVersion record, which means that even if we set null in the VersionData field, it won’t change anything. 

API Integration Hurdles

Problem description: An error occurred when uploading some files to the third-party DMS (Database Migration Service) using Rest API. The error was the next – “String length exceeds maximum: 6000000”. 

Tips to solve it: It turned out the problem was that integration was using multipart/form-data content type, and the HTTP request body was manually defined as a string. When the large file was converted to a string using the base64Encode() method, we got an apex error according to the string variable limitation. This means that you need to remember that if you convert the blob file data to a string, the maximum file size you can use is about 4.3 MB. 

But it is better to use a variable with type Blob if possible. For example, if we need to send data through an HTTP request, we can use the setBodyAsBlob() method of HttpRequest, which takes a blob as a parameter. Blob variables have no such restrictions, and you will not face this error.

Final Take

If you manage it to the end, accept our personal gratitude! Now you’re knowledgeable about Salesforce files and their types, Salesforce attachments vs. file differences, architecture, and sharing of Salesforce files from the UI and dev front-end and back-end perspectives.

 Contact Synebo should you require any development assistance, and stay tuned to new blog updates. 

Table of content
How to Work With Salesforce Files: The Basics What Are Salesforce Files? Difference Between Files vs Notes and Attachments Salesforce Salesforce File Management: UI, Architecture, and Development Perspectives Salesforce File Limits Navigating Salesforce File Challenges Final Take
chat Сomments
No comments yet, be the first to leave one!
leave a comment
articles You might be interested in
Complete Guide Salesforce testing
How-to Guides and Tutorials
12 Feb 2024
Complete Guide to Salesforce Testing
Yana Pushkar
Yana Pushkar
16min
Salesforce Marketing Cloud
Salesforce development
26 Dec 2023
Salesforce Marketing Cloud: Complete 2024 Guide
Yana Pushkar
Yana Pushkar
11 min
Working with salesforce files: the basics
How-to Guides and Tutorials
13 Dec 2023
How to Work With Salesforce Files: The Basics
Olexander Orlуk
Olexander Orlуk
14 min
No image available
How-to Guides and Tutorials
21 Nov 2023
How to Get Listed on Salesforce AppExchange
Pavel Vehera
Pavel Vehera
12min
No image available
Salesforce development
14 Nov 2023
20 Questions to Ask Your Potential Salesforce Implementation Partner
Andrii Kliuchka
Andrii Kliuchka
12min
Cover and internal images for blog post the role of communication in outsourcing teams
Salesforce development
07 Nov 2023
Mastering Communication: Strategies for Collaborating with Salesforce Development Outsourcing Team
Pavel Vehera
Pavel Vehera
13min
Tips for choosing the right salesforce consulting partner
Salesforce development
31 Oct 2023
Tips For Choosing the Right Salesforce Consulting Partner
Pavel Vehera
Pavel Vehera
11min
1 (1)
Salesforce development
24 Oct 2023
How to Build an App for Salesforce AppExchange
Pavel Vehera
Pavel Vehera
14min
12
23 Aug 2023
How to Get the Most Out of Salesforce Reporting and Dashboards?
Sergii Romashov
Sergii Romashov
13 min
11
09 May 2023
How Do Slack and Salesforce Work Together?
Sergii Romashov
Sergii Romashov
13 min
10
05 Apr 2023
Salesforce Einstein, or How AI Betters Your CRM?
Alina
Alina
23 min
9
12 Jul 2023
Migration to Salesforce & Data Migration
Sergii Romashov
Sergii Romashov
14 min
8
28 Jun 2023
How Can Salesforce Experience Cloud Help Your Business?
Sergii Romashov
Sergii Romashov
35 min
7
14 Jun 2023
Salesforce Developer Career
Alina
Alina
24 min
6
21 May 2023
Everything You Need to Know About Sales Cloud
Sergii Romashov
Sergii Romashov
39 min
5
17 May 2023
Project Manager Career With Salesforce
Alina
Alina
26 min
4
03 May 2023
What Is Flow, and Why Is Everyone So Obsessed With It?
Sergii Romashov
Sergii Romashov
17 min
3
19 Apr 2023
Salesforce Admin Career
Sergii Romashov
Sergii Romashov
30 min
2
05 Apr 2023
How to Kick-Start Career With Salesforce?
Alina
Alina
24 min
1
28 Aug 2023
Salesforce Products
Sergii Romashov
Sergii Romashov
28 min
No image available
22 Mar 2023
Intro to Salesforce Nerds Podcast
Alina
Alina
4 min
Neurodivergent side of Salesforce
06 Sep 2023
Neurodivergent Side of Salesforce with Paul Ginsberg
Alina
Alina
56 min
36
02 Aug 2023
Salesforce Implementation: Main Challenges and Best Practices
Alina
Alina
13min
Salesforce Nerds are Taking a Break
07 Sep 2023
Salesforce Nerds are Taking a Break
Alina
Alina
3 min
35
17 Jul 2023
What is Salesforce Experience Cloud, and What You Get From It?
Yana Pushkar
Yana Pushkar
10min
1
20 Jul 2023
CI/CD: Transforming Salesforce Development with DevOps
Alina
Alina
16min
33
31 May 2023
How and Why to Use Salesforce for Nonprofits?
Alina
Alina
6min
1
27 Apr 2023
Salesforce Sales Cloud from A to Z
Alina
Alina
6min
image (1)
30 Jul 2023
All Whats and Whys of Ecommerce Automation With the Power of Salesforce
Alina
Alina
4 min
1
30 Mar 2023
Salesforce Licenses: How to Understand and Choose?
Alina
Alina
6min
1
27 Apr 2023
Main Benefits of Classic to Lightning Migration
Alina
Alina
4min
1
14 May 2023
What is Salesforce Flow, and Why Do You Need It?
Sergii Romashov
Sergii Romashov
4min
15 Types of Salesforce Clouds
19 Jan 2023
15 Types of Salesforce Clouds
Yana Pushkar
Yana Pushkar
11 min
1
06 Dec 2022
5 Examples of the Best CRM for Nonprofit Organizations
Alina
Alina
5min
1
04 Nov 2022
What Is Hybrid Work, And How to Make It Work?
Alina
Alina
5min
1
05 Aug 2022
Salesforce Security in Plain Words
Alina
Alina
7min
1
08 Apr 2022
We Help Ukrainians Take the Salesforce Developer Course
Kristina
Kristina
4min
1
10 Mar 2022
21 Best Nonprofit Software Tools to Enhance Your Work
Kristina
Kristina
16min
1
30 Aug 2022
What is Beneficial in CRM for Nonprofits?
Kristina
Kristina
7min
1
25 Jan 2023
CMS Hub: The Guide to Managing Your Website
Kristina
Kristina
10min
1
10 Aug 2021
How to Find the Best Company for Developing Your Org in Salesforce
Synebo
Synebo
3min
1
17 Mar 2023
What is Salesforce Product Development Outsourcer (PDO)?
Synebo
Synebo
4min
1
28 Jul 2018
3 Steps for Salesforce App Development Lifecycle
Synebo
Synebo
4min
1
16 Apr 2018
How to Deploy Angular App to Salesforce: Developer Insights
Synebo
Synebo
6min
1
29 May 2018
How to Start Salesforce Career with Salesforce Certification
Synebo
Synebo
5min
1
How-to Guides and Tutorials
05 Apr 2018
How to Send Emails via Outlook API from your Salesforce Org
Anastasia Sapihora
Anastasia Sapihora
7 min
1
29 Mar 2019
4 Reasons Why You Shouldn’t Be Afraid of Outsourcing Software Development
Synebo
Synebo
4min
1
18 Feb 2022
The Anatomy of Dynamic Programming [with Codes and Memes]
Oleksandr Alieksienko
Oleksandr Alieksienko
11min
1
16 Feb 2018
6 Examples of UI/UX Design Mistakes and How to Avoid Them
Synebo
Synebo
6min
1
24 Oct 2022
Social Media CRM, or How to Get Closer to Your Customers
Alina
Alina
4min
phone