33 | Convert Notes to Enhanced Notes 34 |
35 |43 | Please consult the FAQ on the project home page. 44 |
45 |54 | If you encounter an issue not mentioned there or have an idea for a new feature or improvement, 55 | you can submit an issue on the project's issue tracker. 56 |
57 |28 | Convert Notes to Enhanced Notes 29 |
30 |104 | © 2017 Douglas C. Ayers. 105 | View project on GitHub. 106 | Licensed under BSD-3 License. 107 |
108 |27 | Convert Notes to Enhanced Notes 28 |
29 |35 | ContentNotes, as compared to old notes object, have more powerful sharing options; let you use rich text, lists and images; and relate notes to multiple records. 36 |
37 |38 | Please take a moment to carefully review your conversion sharing options below. 39 |
40 |33 | Convert Notes to Enhanced Notes 34 |
35 |41 | Schedule how often new notes should be converted to enhanced notes. 42 |
43 |44 | This may be necessary because notes might still be created after initial conversion for various reasons, 45 | such as from user uploads or integrations. 46 |
47 |77 | Enable Note Trigger 78 |
79 | 80 |81 | If you have integrations that create new notes, this trigger will submit a background job to convert them to enhanced notes as they are inserted. 82 |
83 | 84 |85 | Please carefully review your conversion and sharing settings before enabling this option. 86 |
87 | 88 |
89 |
90 |
111 | Schedule Job 112 |
113 | 114 |
115 | Schedule a recurring job to convert new notes to enhanced notes.
116 |
117 | You might consider this option if you have scenarios where new notes are created but are not causing the trigger to fire.
118 |
119 | Click here to be taken to the Schedule Job page in Setup, or follow below directions.
120 |
123 |
134 | Please carefully review your conversion and sharing settings before enabling this option. 135 |
136 | 137 |tag would get escaped, doh! 109 | if ( String.isBlank( noteBody ) ) { 110 | noteBody = '
'; 111 | } 112 | 113 | // We set the owner of the new content note to be the 114 | // same as the note's owner because both fields 115 | // must have same value to insert the content note. 116 | // If they do not match then we get error: 117 | // "Documents in a user's private library must always be owned by that user." 118 | // The other reason to reference the old record's owner 119 | // is if the original creator is inactive and the admin 120 | // needs the new converted file to be owned by an active user. 121 | // The owner of records can be changed, the created by cannot. 122 | 123 | ContentVersion newNoteVersion = new ContentVersion( 124 | // data fields 125 | title = oldNote.title, 126 | versionData = Blob.valueOf( noteBody ), 127 | pathOnClient = oldNote.title + '.snote', 128 | firstPublishLocationId = oldNote.parentId, 129 | sharingPrivacy = ( oldNote.isPrivate ? 'P' : 'N' ), 130 | // custom fields for history tracking and conversion purposes 131 | original_record_id__c = oldNote.id, 132 | original_record_parent_id__c = oldNote.parentId, 133 | original_record_owner_id__c = oldNote.ownerId, 134 | // audit fields 135 | ownerId = oldNote.ownerId, // system requirement, owner and creator must be the same 136 | createdById = oldNote.ownerId, 137 | createdDate = oldNote.createdDate, 138 | lastModifiedById = oldNote.lastModifiedById, 139 | lastModifiedDate = oldNote.lastModifiedDate 140 | ); 141 | 142 | // if communities are enabled then assign network id 143 | if ( communitiesEnabled ) { 144 | newNoteVersion.put( 'NetworkId', this.networkId ); 145 | } 146 | 147 | newNoteVersions.add( newNoteVersion ); 148 | 149 | } 150 | 151 | if ( newNoteVersions.size() > 0 ) { 152 | 153 | SavePoint sp = Database.setSavepoint(); 154 | 155 | try { 156 | 157 | Database.DMLOptions dmo = new Database.DMLOptions(); 158 | dmo.optAllOrNone = false; 159 | 160 | List27 | Convert Notes to Enhanced Notes 28 |
29 |35 | Configure and submit a one-time conversion job. 36 | You may repeat this process as often as you need. 37 | Notes that have already been converted will be skipped so that duplicate enhanced notes are not created. 38 |
39 |79 | You may test on a small set of records by specifying one or more note parent record ids, 80 | otherwise all notes will be converted. 81 |
82 |
100 | The maximum number of files and enhanced notes that can be published in a 24-hour period is 200,000. (documentation)
101 |
102 | This includes files and enhanced notes created from conversion or files and enhanced notes that users create.
103 |
104 | Salesforce's API does not let us know how many have been published within the 24-hour period
105 | so there is no easy way to check and avoid hitting the limit.
106 |
107 | To help mitigate hitting this limit you may provide a Max Records to Convert number to set your own limit and the batch job will stop converting notes to enhanced notes
108 | when either:
109 |
140 | Same purpose and reason why you might set the Batch Size when using Data Loader,
141 | you may want to increase or decrease this value (1 minimum, 200 maximum) for performance reasons.
142 |
143 | If you have other Apex Triggers on ContentVersion, ContentNote, or ContentDocumentLink objects that themselves
144 | perform SOQL queries or insert/update/delete records then that may risk hitting governor limits around
145 | max number of queries that can be made or DML statements. Recommendation, either disable the other Apex Triggers or reduce Batch Size.
146 |
173 | Make sure you have carefully reviewed your conversion and sharing settings 174 | and have made any necessary data backups. 175 |
176 |
',
82 | parentId = account.id,
83 | ownerId = user1.id,
84 | createdById = user1.id
85 | );
86 |
87 | Note githubIssue8 = new Note(
88 | title = 'Meeting Agenda 2016-06-16 agenda.pdf',
89 | body = 'Meeting Agenda 2016-06-16 agenda.pdf',
90 | parentId = account.id,
91 | ownerId = user1.id,
92 | createdById = user1.id
93 | );
94 |
95 | Note[] notes = new Note[] { emptyNote, plainNote, specialTitleNote, specialBodyNote, specialTitleAndBodyNote, htmlBodyNote, githubIssue8 };
96 |
97 | // ensure user1 owns the records
98 | System.runAs( user1 ) {
99 | insert notes;
100 | }
101 |
102 | notes = [
103 | SELECT
104 | id, parentId, ownerId, title, body, isPrivate,
105 | createdById, createdDate, lastModifiedById, lastModifiedDate
106 | FROM
107 | Note
108 | WHERE
109 | id = :notes
110 | ];
111 |
112 | Test.startTest();
113 |
114 | List