Importing Notes to the ContentNote object using the Apex Data Loader
|Knowledge Article Number||000230867|
|Description||With API version 32.0 and later, API support was added for the new ContentNote object, which contains records created using the enhanced/rich-text Note feature. The rich text Note feature in turn was made generally available in the Salesforce user interface as outlined in the Summer '15 Release Notes.
Rich-text notes can be created in the Salesforce user interface. However customers may also wish to import legacy notes stored on a local file system into ContentNote in their Salesforce organization.
This article describes the process for using the Apex Data Loader to accomplish this kind of import.
NOTE: In order to import into ContentNote, you must have both Chatter and the new rich text Notes feature enabled in your Salesforce organization. For instructions for how to enable and setup the new Notes feature in your organization, please see:
|Resolution||Step 1. Preparing your CSV file
You will need to prepare a CSV file with two columns mapping the values for each row you wish to insert:
Title - The title of the note.
Content - The path on your local system to the .txt or .html file that contains the body of the note.
These fields are the only two available for insert, update, and upsert actions. No other fields may be mapped during one of those functions.
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
NOTE: Because ContentNote is based on Salesforce CRM Content functionality, the Content column must contain a path to a local file. The body of the note may not be contained within the CSV file.
Step 2. Preparing the Notes body files on your local hard drive
Each note that you wish to insert should have a corresponding .txt or .html file on your local hard drive that contains the body (Content) of the note itself. These files are the ones that are mapped in the CSV file created at step 1.
Certain special HTML characters are not supported when importing .txt and .html files to the Content field of the ContentNote object. To successfully import files, these 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:
Step 3. Inserting the Note with the Apex Data Loader
If you prepared your CSV file and import files as noted above, you should now be ready to import your legacy Notes!
1. Install and Launch the Apex Data Loader.
2. Click "Insert".
3. Enter your login credentials.
4. Click "Next".
5. Check the box next to "Show all Salesforce objects"
6. Select "Note (ContentNote)" from the list of available objects. (If you don't see ContentNote listed, you may need to enable the new Notes feature for your org.)
7. Click "Browse..." and select the CSV file you created at step 1.
8. Click "Next"
9. When the Data Selection initialization dialog appears, confirm the number of records is correct and click "OK".
10. Click "Create or Edit a Map" on the next screen.
11. Click "Auto-Match Fields to Columns" or manually match the Title and Content fields to the corresponding columns of the CSV file.
12. Click "OK" to proceed.
13. Confirm the mapping is correct and click "Next"
14. Click "Browse..." and specify the location for the success and error files.
15. Click "Finish".
16. Review the Warning and if you're ready to proceed, click "Yes".
Step 4. Relating the inserted Note to a Parent Record with the Apex Data Loader
Once the Note is inserted we need to relate it to the parent record. Since the note is stored in Content, we need to insert a record to the Content Document Link table in order to do this.
1. Create a new csv file with the following columns: ContentDocumentId, LinkedEntityId, ShareType, and Visibility
2. Locate the success log from the Note import (Step 3 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.
3. Populate the LinkedEntityId column with the id of the record that you want to relate the Note to.
4. 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)
5. Launch the Apex Data Loader.
6. Click "Insert".
7. Enter your login credentials.
8. Click "Next".
9. Check the box next to "Show all Salesforce objects"
10. Select "Content Document Link(ContentDocumentLink)" from the list of available objects.
11. Click "Browse..." and select the CSV file you created in the earlier steps.
12. Click "Next"
13. When the Data Selection initialization dialog appears, confirm the number of records is correct and click "OK".
14. Click "Create or Edit a Map" on the next screen.
15. Click "Auto-Match Fields to Columns" or manually match the fields to the corresponding columns of the CSV file.
16. Click "OK" to proceed.
17. Confirm the mapping is correct and click "Next"
18. Click "Browse..." and specify the location for the success and error files.
19. Click "Finish".
20. Review the Warning and if you're ready to proceed, click "Yes". At this point if you view the Notes related list under the Parent record the Note should now be visible.
Tips for trouble-shooting ContentNote insert errors.
ContentNote currently provides a generic error like "Note could not be saved." whenever an issue is encountered while parsing the Note file itself. This is often an indication of an issue with the contents of the text body (Content) file, such as special character(s) that have not been properly escaped.
To resolve the error, you'll need to pinpoint the affected file or files and replace the special characters with their HTML character code equivalent as described in step 2.
If Data Loader reports errors on all the files in your insert, but you're able to confirm based on inspection that at least some of the files have no special characters, then follow these instructions to pinpoint the affected files:
1. Set your data loader batch size to 1.
2. Reattempt the import by following Step 3 above. You may see some files successfully imported.
3. If you receive errors this time, review the error file from the import to see which rows in the CSV file produced an error.
4. If the error file gives the "Note could not be saved" error for any rows, review the .txt or .html file associated with that row and replace the special characters in that file with their HTML character code equivalent as described in step 2.
5. If there are any other kinds of error messages, review and resolve those messages as well.
If you require assistance with determining how to resolve any other errors that can't be answered by searching the Salesforce Help documents, please log a case with Salesforce Support.
6. Reattempt the import, using the Error file for the previous import as your CSV import file, again by following Step 3 above.
See ContentNote insert error: Note Can't Be Saved Because It Contains HTML Tags Or Unescaped Characters That Are Not Allowed In A Note for additional details
Winter '16: New Note button is missing on the Notes & Attachments related list
Create Notes and Add Them to Records in Salesforce Classic
Create Notes and Add Them to Records in Salesforce Lightning Experience
Considerations for enabling the enhanced note-taking tool (Notes) and using Files
|Content Note Import.csv||0KB|