You need to sign in to do that
Don't have an account?

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
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
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.
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,
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?
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
I'm confused... you said it's coming back false but default is checked (true)?
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 :)