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
Vimarsh SaxenaVimarsh Saxena 

Trigger not firing in Sandbox

Hi,

I am trying to create an after insert trigger that would work on ContentDocument and create a new task record based on the type of ContentDocument. I have to go this route of creating trigger because Process Builder and Flows cannot be used with ContentDocument. I am a newbie to development and had given a shot in my Sandbox first. I believe the code is right because I don't see any syntax errors but it's actually not working. Can't figure out what's wrong. Any help is greatly appreciated! Below is my trigger:

 

trigger EmailUpload on ContentDocument (after insert) {
  List <Task> newtask = new List <Task> ();
    
    for (ContentDocument c : Trigger.new) {
        
        
        // here is where you check if content document uploaded is of MSG format
        if (c.FileExtension == 'msg') {
        
        Task t = new Task (); //instantiate the object to put values for future record
        
        // now assign field values to Task object that is being created
        t.Subject = 'New Email';
        t.ActivityDate = SYSTEM.TODAY();
        t.OwnerId = c.CreatedById;
        newtask.add(t);
        
        }    //end if
    }        //end for loop
    
    //once loop is done, insert new records in SF
    // dml operations might cause an error, so catch it with try/catch block.
    try {
        insert newtask; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
}

AbhinavAbhinav (Salesforce Developers) 
Hi Vimarsh,

Please refer below link for similar scenario
https://salesforce.stackexchange.com/questions/16441/trigger-on-contentdocument
Please marks it best answer if it helps.
Thanks!
Vimarsh SaxenaVimarsh Saxena
Thanks Abhinav but the link you shared didn't help