1

Isn't it possible to update Content Version using Before Insert or Update trigger.

I have to update tags for a Content Version. PFB the code.But it is not working somehow. I am not even getting any error. Can someone suggest how this can be fixed.

trigger ContentTrg on ContentVersion (Before Insert, Before Update) {
  for(ContentVersion conObj : Trigger.New){
    // If(conObj.TagCsv != null)
     {  SYSTEM.DEBUG('############ conObj.TagCsv ' + conObj.TagCsv + ' Business_Model ' + conObj.Business_Model__c);
           if(conObj.Business_Model__c != null)
            conObj.TagCsv += ', ' + conObj.Business_Model__c ;
           if(conObj.Account__r.Geo_HDS__c != null)
            conObj.TagCsv += ', ' + conObj.Account__r.GEO_HDS__c;

           SYSTEM.DEBUG('############ conObj.TagCsv ' + conObj.TagCsv);
       }

   }
}
4
  • I can't find any error in your code. Are you sure the Business_Model__c and Account__r.Geo_HDS__c fields are not equal to null? Jan 12, 2017 at 9:36
  • Yes, I can see the data appearing in last line of code in debug statement. But it is not updating on the content tag. Jan 12, 2017 at 9:43
  • Do you have several triggers on ContentVersion? Could it be possible that another trigger updates this field after this trigger? Jan 12, 2017 at 9:48
  • No this is only one. Jan 12, 2017 at 10:16

1 Answer 1

4

I believe this is due the following reason "Values for the TagCsv and VersionData fields are only available in triggers if the request to create or update ContentVersion records originates from the API."

Salesforce link - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_ignoring_operations.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .