function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jerrod Knapp 11Jerrod Knapp 11 

I need to update a contentversion field from a custom object

I know that the contentversion object is a tricky monkey but I need to update a custom field (chekcbox) on that object from a related custom object.  Their relation is the contentversion id.  I tried flow and process builder but it's just not working...  I'm hoping that someone can help with a trigger.  Here is how it goes...
when
CustomObject__c.CustomCheckbox__c field gets set to = True
then
ContentVersion.CustomCheckbox gets set to = False

Thanks ahead of time to anyone who gives me a hand with this.
Sincerely,
Jerrod.
Shawn Reichner 29Shawn Reichner 29
I will attempt to help, but not havign the correct object name and field API's there may be some syntax errors, please follow back up with any errors and we can attempt to help further. 

In the meantime try this trigger.....
trigger UpdateContentVersionCheckBox on CustomObject__c (after insert, after update) {

List<ContentVersion> cv = new List<ContentVersion>();

     for(CustomObject__c co : Trigger.new){
          if(co.CustomCheckbox__c == True) {
             cv.add(co.ContentVersion__r.Id);
          }
     }
If(cv.size()>0){
cv.CustomCheckbox = True;
}
}

Let me know if this helps, or if you hit any errors,

Shawn​
Jerrod Knapp 11Jerrod Knapp 11
Thanks for the quick response, below is the edited code with my custom object:

trigger UpdateContentVersionCheckBox on DocumentProxy__c (after insert, after update) {

List<ContentVersion> cv = new List<ContentVersion>();

     for(DocumentProxy__c dp : Trigger.new){
          if(dp.ProcessApproved__c == True) {
             cv.add(dp.ContentVersion__r.Id);
          }
     }
If(cv.size()>0){
cv.Not_On_Web__c = True;
}
}

I get this error:  Error: Compile Error: Variable does not exist: ContentVersion__r at line 7 column 24
Jerrod Knapp 11Jerrod Knapp 11
I think I need to clariy that there is no way to relate those two objects.  I think this is where the error is happening.  What I do have is on the custom object I have a field that pulls the ContentVersion Id.  So somewhere it would need to state:  where ContentVersion.Id = dp.contentversionid
Shawn Reichner 29Shawn Reichner 29
Oh so this field is not a lookup to set the relation ship between the records? Can you share a little more about the schema for these two objects?