function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chidanand MChidanand M 

Trigger on Attachment/ContentDocument/ContentDocumentLink in Lightning Environment

Hi All,

I have written a trigger on contentdocument object to get the size of the file that is being uploaded. Unfortunately, everytime i upload the document i get size of the file being uploaded as null. Let me know if anybody has faced the same issue and resolved it. 

Thanks and Regards
Chidanand G.M.
Chidanand MChidanand M
Below is my trigger.

trigger filesSizeConDoc on ContentDocument (before insert) {
    
    list<ContentDocument> att = new List<ContentDocument>();
    for (ContentDocument a : Trigger.new) { 
        system.debug('=size-content size='+a.ContentSize);
        att.add(a);    
    }
    integer sizecheck = att.get(0).ContentSize;
    if (sizecheck  > 1000){
        att.get(0).addError('max size 1 Mb');
    }

}