Skip to main content
Hello, I have a picklist named "Dokumentenklasse__c" on Content Version. If a file is uploaded and the value "Geschäftsbrief" is selected the file should be able to be saved. But when somebody tries to edit the details of the File I want the VR to block it. Could you tell me how to achive it?
1 answer
  1. Jun 27, 2021, 6:06 AM
    Hi Jonathan,

    You can try handling the validatio via trigger like below sample code :- 

    trigger ContentVersionTrigger on ContentVersion (before delete) {

    Set<Id> contentDocumentIdSet = new Set<Id>();

    if(trigger.IsDelete){

    for(ContentVersion con : Trigger.old){

    if(con.ContentDocumentId != null)

    {

    contentDocumentIdSet.add(con.ContentDocumentId);

    }

    }

    ContentDocumentLink cdl = [SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN:contentDocumentIdSet Limit 1];

    for(ContentVersion con : Trigger.old){

    if(con.Dokumentenklasse__c =='Geschäftsbrief'){

    if(cdl!=null){

    con.addError('You cant edit the file');

    }

    }

    }

    }

    }

    If this works, please mark it as best answer.

    Regards,

    Priya Ranjan

0/9000