Loading

ContentVersion before trigger is not applying changes when uploading a new version of file from Files Tab

Udgivelsesdato: Sep 15, 2025
Beskrivelse

The 'before insert' trigger on the ContentVersion object won't apply any changes to a custom field when uploading a new version of a file from the Files Tab. The value set by the before trigger will be overwritten with the previous version's value.

If there's no default value set while uploading a new file, it will be null.

- Expected result:
Custom fields is populated with a designated value.

- Actual result:
Custom field isn't populated.

Steps To Reproduce:


(1) Create a custom field on the ContentVersion object (e.g., "Custom_Data__c", Text, 255 characters)
(2) Create an Apex trigger on ContentVersion with before insert and after insert events:
===================================================
trigger ContentVersionTrigger on ContentVersion (before insert, after insert) {
if (Trigger.isBefore && Trigger.isInsert) {
for (ContentVersion cv : Trigger.new) {
cv.Custom_Data__c = Datetime.now().toString();
}
System.debug(Trigger.new[0].Custom_Data__c);
}
if (Trigger.isAfter && Trigger.isInsert) {
System.debug(Trigger.new[0].Custom_Data__c);
}
}
===================================================
(3) Navigate to the Files tab in Lightning Experience
(4) Upload a new file and verify the "Custom_Data__c" field shows the correct timestamp in the file details
(5) Upload a new version of the same file
(6) Observe that the "Custom_Data__c" field shows the timestamp from the original file upload rather than the new version upload time

 

 

Løsning

Move the custom field logic entirely to an after insert trigger for new versions.

Vidensartikelnummer

005167128

 
Indlæser
Salesforce Help | Article