• -1 Points
  • Member since 2020

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2
I have a requirement to share a note with multiple accounts. My first issue I was trying to solve is being able to store the notes data in variables then create new records based off that data. I have a trigger on ContentDocumentLink that passes info off to a class. 

Problem is, if I save the note before it auto saves, everything works. If I let the record auto save, I dont get the body of the note. 
trigger trasnferNotes on ContentDocumentLink (after insert) {
    string relatedID;
    String documentID;
    //Get the current ID for the note
    if (Trigger.isAfter) {
        if (Trigger.isInsert) {
            for(ContentDocumentLink cdl : Trigger.New) {
                relatedID = cdl.LinkedEntityId;
                documentID = cdl.ContentDocumentId;
                transferNotesClass db = new transferNotesClass(relatedID, documentID);
global class transferNotesClass {
    global String noteID;
    global String contentDocumentID;
    global String cvID;
    global transferNotesClass(String relatedID, String documentID) {
        try {
            noteID = relatedID;
            contentDocumentID = documentID;
            System.debug('Class Note ID: ' + noteID);
            //Getting the ID from ContentVersion
            List<ContentVersion> cv = New List<ContentVersion>([select id from ContentVersion 
                                                                where ContentDocumentId = :contentDocumentID]);
            for(ContentVersion cv1 : cv) {
                cvID = cv1.Id; 
            //Getting the Content Note by passing the above ID to ContentNote
            List<ContentNote> contNote = New List<ContentNote>([select Content, ContentSize, CreatedById, CreatedDate, FileExtension, FileType, 
                                                                Id, IsDeleted, IsReadOnly, LastModifiedById, LastModifiedDate, LastViewedDate, 
                                                                LatestPublishedVersionId, OwnerId, SharingPrivacy, TextPreview, Title 
                                                                from ContentNote where LatestPublishedVersionId = :cvID]);
            for(ContentNote contNote1 : contNote) {
                Blob contentBlob = contnote1.Content;
                String contentString = contentBlob.toString();
                List<String> csvFileLines= contentString.split('\n');
                System.debug('Note Title: ' + contNote1.Title);
                //System.debug('Note Content: ' + csvFileLines);
        catch(DmlException e) {
            System.debug('The following exception has occurred: ' + e.getMessage());


When someone takes the time/effort to repspond to your question, you should take the time/effort to either mark the question as "Solved", or post a Follow-Up with addtional information.  


That way people with a similar question can find the Solution without having to re-post the same question again and again. And the people who reply to your post know that the issue has been resolved and they can stop working on it.