• Prahlad .
  • NEWBIE
  • 0 Points
  • Member since 2021
  • Student
  • modapkfile

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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(csvFileLines);
                System.debug('Note Title: ' + contNote1.Title);
                //System.debug('Note Content: ' + csvFileLines);
            }
            
        }
        
        catch(DmlException e) {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
        
    }
    
}