0

I figured out this code where I send id and message via params, but i need ONE single note related to multiple records, not a note for each record

   public static void crearNotas(String casoid, String mensajenota){
    //creamos notas para los casos relacionados
    System.debug('Nota creada para el caso: ' + casoid + 'con el mensaje: '+ mensajenota);
    ContentNote objCntNote = new ContentNote();
    objCntNote.Title = 'Casos Relacionados';
    objCntNote.Content = Blob.valueOf(mensajenota);
    insert objCntNote; 

    //Creamos ContentDocumentLink hacia el id del caso
    ContentDocumentLink objCntDocLink = new ContentDocumentLink();
    objCntDocLink.LinkedEntityId = casoid; 
    objCntDocLink.ContentDocumentId = objCntNote.Id;  
    objCntDocLink.shareType = 'V'; 
    insert objCntDocLink;
}

Thank you :D

sirlegrau
  • 25
  • 4

1 Answers1

1

Create more ContentDocumentLink records. Each ContentDocumentLink is a junction between a linked object and a Note or File that's attached. The LinkedEntityId is the Id of the record to which you wish to link the note.

If your caller needs to specify the related records, change String casoid to a List<Id>, and iterate over it to create your links. Make sure to create records in a List<ContentDocumentLink> and perform one insert DML outside the loop.

David Reed
  • 2,522
  • 2
  • 16
  • 16