Overcoming Salesforce Attachment Limitations with External File Storage
Salesforce enables adding file attachments to accounts, opportunities and other objects.
Attachments are visible in the Notes & Attachments section in record details. They can be added to both standard and user-defined objects — the latter is important for custom objects provided by packages extending the standard CRM functionality (for example, most Nextian custom objects such as work orders support attachments).
The standard attachments feature works reasonably well, especially with the new Lightning ‘Files’ implementation, which has replaced the legacy classic ‘Attachments’ (migration is automatically handled when switching to the Lightning experience).
However, for businesses that rely heavily on documents, the standard Salesforce functionality may be insufficient due to:
|
Available Options
Depending on business objectives and needs, options for enhancing file attachments can be categorized as follows:
Option | Vendors/Packages | Pros | Cons |
---|---|---|---|
Using built-in attachments and purchasing additional storage | No changes required (just pay). | Does not address any limitations outlined above. | |
Using external file storage |
| Larger (in some cases unlimited) storage, good search capabilities. Good integration can enable users to spend 100% of their work time in Salesforce without having to switch between the systems. | Coding in Lightning and APEX may be required. Document migration from Salesforce to the new storage system might be a challenge. |
Integration with a fully-blown Document Management System (DMS) |
| Has all the pros of using external file storage enhanced with DMS features (document generation, workflows, approvals, etc.). Best choice for businesses building their processes around document flows. | Usually a large project, associated with a DMS rollout. |
Built-in Attachments
Understanding built-in Salesforce attachments is a good first step for choosing a replacement and understanding potential security and migration issues.
First, it’s essential to note that object storage and file storage are separate (Setup → Company Information):
Understanding Salesforce Attachment Structure
Attachments are linked to documents via the following tables:
ContentDocumentLink → ContentDocument → ContentVersion
ContentDocumentLink links parent object ids such as opportunity, account, etc. with the documents. The following SOQL query can be used to retrieve links for any Salesforce object:
SELECT ContentDocumentId, /* id of document linked to parent*/ ShareType /* sharing mode, e.g. 'V' view only, 'I' infer from record permissions */ FROM ContentDocumentLink WHERE LinkedEntityId = '0015g000003YnHlAAK' /* parent object id, = or IN operators must be present */
The LinkedEntityId in the query represents parent object id.
ContentDocumentLink can only be queried using a specific id or a set of ids with the IN clause. Examining larger sets of attachments requires downloading data via Data Loader, a backup or a database replication tool.
Pro Tip | Object key (the first three characters of LinkedEntityId) can be used to obtain statistics on attachments per object type. |
The value of ContentDocumentId from the query above can be used to query document properties:
SELECT Title, FileType, FileExtension, Description FROM ContentDocument WHERE Id = '0695g000000gG0UAAU'
This does not however return the document content. Since content is versioned and has to be pulled from the ContentVersion table:
SELECT Id, IsLatest FROM ContentVersion WHERE ContentDocumentId = '0695g000000gG0UAAU'
Attachment Security Model
The ShareType field on ContentDocumentLink (in the query above) determines how a particular attachment is shared:
- ‘V’ – creator full access, other users view only
- ‘I’ – infer from object (i.e., follow permissions on the particular record)
- ‘C’ – creator full access, other users must be granted access
The Salesforce org default is ‘V’ however it can be changed to ‘I’ via Setup → Feature Settings → Salesforce Files → General Settings and checking Set file access to Set By Record for files attached to records:
Unfortunately, this option works for new attachments only and existing records must be changed with the Data Loader or other tool.
Important | Most external storage add-ons (e.g., BOX.COM) support some sort of equivalent of the ‘I’ sharing type. |
Using External File Storage — Considerations
Integration effort will depend on the selected storage provider. For example, making Google Drive or Microsoft SharePoint files available for individual users via Files Connect is a considerably smaller effort than a complex BOX.COM integration.
Regardless of external storage chosen, a typical integration involves:
- Modifying Lighting record pages to embed new external access components.
- Migration of existing documents from Salesforce native to external storage attachments.
- Optional migration of documents from other sources.
- Automated creation of documents folders and sub-folders.
- Creation and association of folders for existing records that do not have attachments yet.
- Administrative lighting actions — there are chances that things will go wrong so actions like ‘Create Folder Structure’ need to be made available to system administrators.
- Security and audit configuration.
It’s clear from the scope above that some development in APEX and Lightning is required. Additionally, migrating documents from sources outside Salesforce typically involves orchestrating the Salesforce REST API, storage API (some vendors offer an SDK that simplifies this process), data transfers, and migration logic written outside of Salesforce, such as in Python, Java, C#, or other programming languages.
Conclusions
Choosing an alternative external file storage solution for Salesforce can be challenging due to the wide range of options and varying business requirements. Implementation and file migration may also require significant effort and careful project planning.
Contact us today to find out how we can help you!