Created
June 25, 2015 20:22
-
-
Save ryanguest/65a4ea1152455716fb12 to your computer and use it in GitHub Desktop.
ContentDocumentLink example from Apex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String ACCOUNT_ID = '001D000000K2ES6'; | |
ContentNote n = new ContentNote(); | |
n.title = 'My Note from Apex'; | |
insert n; | |
ContentDocumentLink link = new ContentDocumentLink(); | |
link.LinkedEntityId = ACCOUNT_ID; | |
link.ContentDocumentId = n.id; | |
link.ShareType = 'V'; | |
link.Visibility = 'AllUsers'; | |
insert link; |
@muchavie, ShareType determines the accessibility to the uploaded file.
I - Inferred permission ( Not accessible to others)
C - Collaborator
V - Viewer
I tried this with adding a note to an event but get the error
"First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Document]: [Document]".
My code is:
ContentNote cn = new ContentNote();
cn.content=Blob.valueOf(noteforevent.escapeHTML4());
cn.title='Note on event';
ContentDocumentLink link = new ContentDocumentLink();
link.LinkedEntityId = eventID; //eventId is coming in with valid content!!
link.ContentDocumentId = cn.id;
link.ShareType = 'C';
link.Visibility = 'AllUsers';
insert link;
Enabling this triggers gives error to community user while creating Notes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! I had no idea what the values of ShareType could take. 'V' works!