1. Salesforce Files & Enhanced Notes
1.1 Files
Salesforce files allows users to
- Collaborate with coworkers by posting files to feeds and directly to records, such as Accounts, Cases, Leads, and more.
- Share files with customers in the secure Salesforce cloud.
- Sync files between your local drive and Salesforce.
- Learn how users work with files by running standard and custom file reports.
- Have multiple versions of same file.
- Have file of size upto 2 GB
1.2 Enhanced Notes
- Notes is built on top of Salesforce Files, so you can do many of the same things with notes that you can do with files, such as report on notes and use Chatter to share notes. With the Enhanced Note-taking tool over legacy Notes users can
- Create standalone notes (not related to records)
- Relate notes to multiple records
- Use rich text formatting, including bulleted and numbered lists
- Search Salesforce for just notes
- And many more
2. Migrating from “Notes & Attachments” to “Notes & Files”
In the Winter’16 release, Salesfroce introduced Files related list, that can be added to page layouts. In Spring’16salesforce provides an option, so when users upload files using Attachments related list, they goto Files object not the Attachments. Considering above features and enhancements, NTN decided to use Files & Notes instead of the Notes & attachments.
3. Problem Statement
There is no official / unofficial document that is as of this day, outlines the steps to upload Files (ContentDocument) nor anything related to migration from Attachments to Files.
4. Files data loading
4.1 Content Document Objects ERD
4.2 Data loading steps for Files
- Export Attachments data using data loader.
- Export Attachments files, using data export wizard or File exporter.
- Create two fields, ParentId and AttachmentId on ContentVersion object
- ParentId will hold the id of the entity, attachment was linked to.
- AttachmentID (with unique constraint) will hold the id of the attachment from attachment object.
- Create a CSV, ContentVersion_upload.csv, for ContentVersion with the following fields
- Attachment_id (AttachmentId from file exported in step-1)
- ISDELETED
- PARENTID (Entity Id of the object, from file exported in step 1)
- Versiondata (local file path)
- PathOnClient (local file path)
- Title (title of the file)
- OWNERID
- DESCRIPTION
- Upload (Insert) ContentVersion.csv.
- Export ContentVersion data uploaded in step-5.
- Create another CSV for ContentDocumentLink (and update ContentDocumentID and ParentEntityId, from the ContentVersion file exported in step-5) with the following fields:
- CONTENTDOCUMENTID (ContentDocumentId from file exported in step-6)
- LINKEDENTITYID (ParentId from file exported in step-6)
- SHARETYPE
- VISIBILITY
- Upload (Insert) ContentDocumentLink.
5. Notes data loading
5.1 Content Notes Objects ERD
5.2 Data loading steps for Notes
- Export Notes data using data loader.
- To successfully import files, certain special characters will need to be converted to a supported HTML character code equivalent prior to import. Below is a list of unsupported characters and their suggested HTML character code replacement:
- Convert Note Body to individual text file
- Since enhanced notes are part of Salesforce content, it requires “.txt” or “.html” files to be uploaded. Hence, body of the notes downloaded in step-1 need to be converted to “.txt” files before they can be used in CSV preparation. Physical path of the files created from this conversion will be used in next step.
- Prepare CSV file with following fields
- Title (Title of the note)
- Content (Local file path of the note)
- Prepend file path to the ‘Title’ column, if Note Body is converted as mentioned below then physical file should be created with the Title name and append “.txt”.
- Insert Notes (ContentNote) with data loader
- Export ContentNote data.
- Create another CSV for ContentDocumentLink with the following fields:
- CONTENTDOCUMENTID (ContentDocumentId from file exported in step-6)
- LINKEDENTITYID (ParentId from file exported in step-6)
- SHARETYPE
- VISIBILITY
- Locate the success log from the Note import (Step 4 above) and populate the ContentDocumentId column in the new file with Id value from the success files for the Notes that you want to relate to records.
- Populate the LinkedEntityId column with the id of the record that you want to relate the Note to.
- Set the ShareType and Visibility fields as desired. Documentation here describes the valid values for these fields and their function, there is also an example insert file attached to this article. Repeat as needed for further records then save your file.(Please note that you can only specify the values 'I' or 'V' for the standard objects since type 'C' is not supported)
- Upload contentDocumentLink.
Find Special Character | Replace with... |
& | & |
< | < |
> | > |
" | " |
' | ' |
P.S. There are other formatting options available here. e.g. line breaks, etc.
SAMPLE TABLE:
Title | Content |
Test Note 1 | C:\notes\test_note_01.txt |
Test Note 2 | C:\notes\test_note_02.html |
Test Note 3 | C:\test_note3.txt |
5.3 Note Body conversion to “.txt” files
Create a macro (vba) to export note body to text files. To create excel macro follow these steps:
1. Go to View Tab
2. Macros > Record Macro
3. Enter a name for the macro
4. Macros > View Macro
5. Click on the macro you created in step - 3
6. Click "Edit" button
Or refer this link (http://www.excel-easy.com/vba/create-a-macro.html)
7. Enter the VB code given below in the macro and edit column heading as per your sheet.
7. Enter the VB code given below in the macro and edit column heading as per your sheet.
Sub Export_Files()
Dim sExportFolder, sFN As String
Dim rNoteName As Range
Dim rNoteContent As Range
Dim oSh As Worksheet
Dim oFS As Object
Dim oTxt As Object
'sExportFolder = path to the folder you want to export to
'oSh = The sheet where your data is stored
sExportFolder = "D:\[Folder location...]\NoteFiles"
Set oSh = Sheet1
Set oFS = CreateObject("Scripting.Filesystemobject")
'Note file name, in the code below, “E” column
For Each rNoteName In oSh.UsedRange.Columns("E").Cells
'Note body is 4 column spaced from Note Title, hence offset with column 4 used.
'change below code as per your CSV file
Set rNoteContent = rNoteName.Offset(, 4)
'Add .txt to the article name as a file name
sFN = rNoteName.Value & ".txt"
Set oTxt = oFS.OpenTextFile(sExportFolder & "\" & sFN, 2, True)
oTxt.Write rNoteContent.Value
oTxt.Close
Next
End Sub
6. References
https://help.salesforce.com/apex/HTViewSolution?urlname=Importing-Notes-to-the-ContentNote-object-using-the-Apex-Data-Loader&language=en_US
ContentNote can't be saved, because it contains HTML tags...
ContentNote can't be saved, because it contains HTML tags...


Trying to following Data loading steps for Files. How is the data for:
ReplyDeleteStep 4:
Versiondata (local file path)
PathOnClient (local file path)
Step 7:
SHARETYPE
VISIBILITY
Sorry, just missed the comments. If you still have questions, please do post specific problem again.
DeleteHey, just wanted to say THANK YOU for this post. Plenty of places cover the fact that you have to load using a directory of text files, but you're the first I found that actually provided the VB to DO it.
ReplyDeleteThanks.
Delete