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); }}2 réponses
Hi Vimarsh,Please refer below link for similar scenariohttps://salesforce.stackexchange.com/questions/16441/trigger-on-contentdocumentPlease marks it best answer if it helps.Thanks!