ContentVersion Reasonchange not updateable?

I have a before update trigger that I want to use to capture updates to previous version records in the contentversion. I want to add additional text to the reasonchange that was added by the user before the record is updated. However when testing, for some reason the newly uploaded version, aka the insert record, is the only record in the batch. Which shouldn’t be right?

This is a test trigger I used to test. It fails indicating ReasonForChange is not writeable.

trigger ContentVersionTrigger on ContentVersion (before update) {
    for(ContentVersion cv : {
        cv.ReasonForChange = 'Testing';

Is there a way to update the previous version’s reasonforchange field upon revision of a published content?


As per docs :
The reason why the document was changed. This field can only be set when inserting a new version (revising) a document.

Refer this for revising an existing document if you did not get a chance to look at this :

Hope this helps.

        // Create a content version object  
        ContentVersion contentVersion = new ContentVersion();

        // Set the mandatory field pathOnClient  

        // Set the binary file data  

        // Set the document ID of the document you wish to revise  
        contentVersion.setContentDocumentId(new ID("069x00000000C0j"));

        // Set the reason for change field on revision  
        contentVersion.setReasonForChange("Added total cost of"
                + "ownership graph");

        // You can add multiple versions if required by adding  
        // them to the array  
        SObject[] array = new SObject[] { contentVersion };
        SaveResult[] saveResultArray = binding.create(array);
        for (SaveResult sr : saveResultArray) {
            if (sr.isSuccess()) {
                System.out.println("created version with id:"
                        +  sr.getId());
            else {
                System.out.println("Failed to create entity");
                for (Error error : sr.getErrors()) {

Source : Link , Question Author : Bryan , Answer Author : Matt Lacey

Leave a Comment