Skip to content


Tech Tuesday: SalesForce Notes and Attachments

SalesForce allows files to be attached to records. These files are stored as Base64 encoded data in the ‘Content Version’ object. SmartConnect can be used to encode these files and upload them to SalesForce. Once the attachment is imported, we will need to use the ‘Content Document Link’ object to link the document to the relevant records in Salesforce. In today’s article we go over the steps to upload a file to SalesForce and link it to a record. In my example I will be attaching a PDF to an existing Account. At the bottom of the article is a download link for the maps used in this example.

Querying Content Version

Querying the data can be tricky, but it is possible to retrieve the latest version of the attachment by filtering on the ContentDocumentLink object.
A query to retrieve all attachments on all accounts would look like:

Create Content Version

Create a map with the following information in the source. You can use a multi-data source if needed to retrieve all the necessary information.

  • Account Id in SalesForce
  • File path of the PDF file
  • Title of the document

We will select ‘Content Document Version’ as the destination object. We will map the SalesForce Id to the Description of the ‘Content Document’. This will give us a unique field to use when we link the Content Document to the Account. We will group our map on the Id field that we mapped to Description, because this is our unique identifier for the Content Document.

Content Document (Version) Mapping


The PDF file can be easily encoded with a calculated column. Here is a sample script for the calculated column.

return System.Convert.ToBase64String(File.ReadAllBytes(_FILE))


Link the Content Document

We will create a second map to link the imported Content Document to the Account record. For my example I used the same data source for my child map and set it as a post map task to link all the newly imported content documents. This map will have a destination object of ‘Content Document Link’.

We will need to map the ContentDocumentID which can be populated using an entity lookup using the Description field on Content Document.  The LinkedEntityId is the Id of the Account record I want linked to this document.



Content Document Link Mapping

Updating an Attachment

There are times when we will need to update a document. SalesForce handles this by allowing for multiple versions of the same document. The only thing that will need to change in our existing map is the Title. If the Title is different, SalesForce will add a new version on the existing document.

You will not need to run the Document Link map on an update, because the existing link is still being used regardless of version. If you try to update a Document Link you will receive errors that you cannot edit the ContentDocumentId and LinkedEntityId.



Keep in mind that SalesForce is a hosted environment so it is not encouraged to store large documents this way unless absolutely necessary. The Salesfoce maximum file size that can be upload via the SOAP API is 50 MB. When a document is uploaded or downloaded via the API, it is converted to base64 and stored in VersionData. This conversion increases the document size by approximately 37%. Account for the base64 conversion increase so that the file you plan to upload is less than 50 MB after conversion.

SF Attachment Maps


Leave a Comment


Q1 2023 All Hands Call
2023 Advanced SmartConnect Bootcamp: REST Web Services Integration
Accessing Your Historical Dynamics NAV Data in D365 Business Central - Part 1: Getting Started
2023 Migration from Dynamics GP to D365 Business Central Training
eOne Welcomes Incremental Group as a New eOne iPaaS Integration Partner


2016 SmartConnect Integration Bootcamps
Tech Tues: Automatically refreshing Pivot Tables in Excel Refreshable Reports
Happy Thanksgiving from the eOne team!
2017 SmartConnect Integration Bootcamps
New Releases of Extender and SmartList Builder



Business Central CRM D365 Business Central Dynamics 365 dynamics crm Dynamics GP Dynamics NAV Econnect Employee Spotlight eone eOne News error Error Message Events Excel Excel Report Builder Extender Flexicoder GP integration Map Meet the Team Microsoft dynamics crm Microsoft Dynamics GP Navigation List Builder Office Relationships Partner All Hands Call Popdock promotions release SalesForce SmartConnect SmartConnect Bootcamp SmartConnect Maps SmartConnect Office Hours SmartList SmartList Builder SmartPost SmartView SQL Tech Tuesday Templates training

Integrate & Automate without Any Code.

SmartList Data has Never Been Faster.

The Easiest Way to Report on GP Data.