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
krishna Mullapudikrishna Mullapudi 

unable to fire trigger on Content Document Obj

Hi all,
I was created the trigger on contentDocument obj for after insert . But when i upoload document from UI in Dev environment the created trigger was not firiing . please help
AbhinavAbhinav (Salesforce Developers) 
Hi Krishna,

Check suggestions provided on below link:

https://salesforce.stackexchange.com/questions/76015/trigger-on-contentdocument-not-working

It will help you understand the issue.

If it helps, mark it as best answer.

Thanks!
 
Lukesh KarmoreLukesh Karmore
Hii 
krishna Mullapudi
I worked on this Sceneario before ,please refer below trigger If helps Please mark Best Ans So It helps other.

trigger sendEmailToContactWhenfileIsCreated on ContentDocumentLink (after insert) {
set<id> condocId=new set<id>();
for(ContentDocumentLink con:Trigger.new){
    if(con.LinkedEntityId!=Null || con.LinkedEntityId!=''){
        condocId.add(con.LinkedEntityId);
    }
}
list<Messaging.singleEmailMessage> mailList= new list<Messaging.singleEmailMessage>();
list<contact> contactList=[select id,Email from contact where id in:condocId];
for(ContentDocumentLink con:Trigger.new){
    for(contact c:contactList){
        list<contentVersion> covVer=[SELECT id,contentDocumentId,Title,versionData FROM contentVersion WHERE contentDocumentId=:con.contentDocumentId];
        Messaging.singleEmailMessage mail=new  Messaging.singleEmailMessage();
        list<string> toaddress=new list<string>();
        toaddress.add(c.Email);
        mail.setToAddresses(toaddress);
        mail.setSubject('your Subject');
        mail.setPlainTextBody('This is first email attachment');
        mailList.add(mail);
        messaging.EmailFileAttachment efa=new messaging.EmailFileAttachment();
        efa.setFileName(covVer[0].Title);
        efa.setBody(covVer[0].versionData);
        mail.setFileAttachments(new messaging.EmailFileAttachment[]{efa});
    }
}
messaging.sendEmail(mailList);
}
Thank You