• Vive Subramani
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hey, I need to attach a csv file to the task record. I could insert it to Account object, but it is not working for Tasks. Could you please let me know if it is possible to insert attachment to Task object.
Sample code below,

ContentVersion conVer = new ContentVersion();
        conVer.ContentLocation = 'S';
        conVer.PathOnClient = 'taskFile.csv'; 
        conVer.Title = 'Task Test Files'; 
        conVer.VersionData = Blob.valueOf(attString);
        insert conVer;  
        
        
        Id conDoc = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;
        ContentDocumentLink conDocLink = New ContentDocumentLink();
        conDocLink.LinkedEntityId = '00T5g00000IbMnyEAF'; //Task Id
        conDocLink.ContentDocumentId = conDoc;  
        conDocLink.shareType = 'C';
        insert conDocLink;

Thanks in Advance!
Hey, I need to attach a csv file to the task record. I could insert it to Account object, but it is not working for Tasks. Could you please let me know if it is possible to insert attachment to Task object.
Sample code below,

ContentVersion conVer = new ContentVersion();
        conVer.ContentLocation = 'S';
        conVer.PathOnClient = 'taskFile.csv'; 
        conVer.Title = 'Task Test Files'; 
        conVer.VersionData = Blob.valueOf(attString);
        insert conVer;  
        
        
        Id conDoc = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;
        ContentDocumentLink conDocLink = New ContentDocumentLink();
        conDocLink.LinkedEntityId = '00T5g00000IbMnyEAF'; //Task Id
        conDocLink.ContentDocumentId = conDoc;  
        conDocLink.shareType = 'C';
        insert conDocLink;

Thanks in Advance!