Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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 : trigger.new) {
        cv.ReasonForChange = 'Testing';
    }   
}

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

share|improve this question

1 Answer

As per docs :

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_contentversion.htm 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 : http://www.salesforce.com/docs/developer/cookbook/Content/revise_document.htm

Hope this helps.

        // Create a content version object  

        ContentVersion contentVersion = new ContentVersion();

        // Set the mandatory field pathOnClient  

        contentVersion.setPathOnClient(
                testUploadFile.getAbsolutePath());

        // Set the binary file data  

        contentVersion.setVersionData(readData);

        // 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()) {
                    System.out.println(error.getMessage());
                }
            }
        }        
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.