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
Gunners_23Gunners_23 

Trigger on Content

Hi all,

I have written a trigger on ContentVersion object. Pls find the code below 

 

trigger docupload on ContentVersion (after insert) {
    List<Task> lstTask = new List<Task>();
    Task newTask;
    List<ContentVersion> lstcon = Trigger.new;
    for(ContentVersion c : lstcon) {
    
        newTask = new Task();
       
       //Here i've added the task status,subject,assigned To and other fields

      //But there is one custom field on contentversion which is checkbox while uploading time i'll set that checkbox and after i will assign that to task custom field

 

      newTask.somefield__c = c.somefield__c; 
        
        lstTask.add(newTask);
     }  
    }
    insert lstTask;
}

 

Eventhough i've assigned that custom fields value to task custom fields its not taking that value even i checked with other data types too its not also not working, my assumption is its firing before the value is set.

 

what am i missing? kindly help

 

 

thank you

Best Answer chosen by Admin (Salesforce Developers) 
Gunners_23Gunners_23

I found out a workaround for this. For this case you can write after update condition instead of after insert which will work fine. 

 

 

cheers :)

All Answers

MattLacey.ax1065MattLacey.ax1065

So it's definitely inserting the new tasks? I'd check that your profile is allowed to write to the field, and that there's no workflow or similar (after insert triggers?) which might be modifying it after you insert it.

Gunners_23Gunners_23

Its creating tasks and everything is working fine, but whatever the custom fields i've created in ContentVersion those values will take default value even though i set values during the upload. 

 

Regards,

MattLacey.ax1065MattLacey.ax1065

Are there any workflows or triggers running on tasks? Sounds like something must be changing them. If you just create a task in the system directly with the right values does it save ok?

Gunners_23Gunners_23

 

There is no trigger on task ....Task is working fine but if i fetch the value of custom field of ContentVersion object  its returning default value i.e false for checkbox as i have given default checked.

 

The problem i'm getting is the value returned from the custom field of ContentVersion is always default its not returning the one i set during upload

MattLacey.ax1065MattLacey.ax1065

I'm confused... you said it's coming back false but default is checked (true)? 

Gunners_23Gunners_23

I found out a workaround for this. For this case you can write after update condition instead of after insert which will work fine. 

 

 

cheers :)

This was selected as the best answer