Archiving ContentDocuments with Criteria from the Parent Object

    This article outlines how to archive a contentdocument with criteria from the parent object for example archiving files that are related to Opportunities when the opportunity is ‘Closed Won’.


    1. A lookup field must be created on the Content Version object in Salesforce.
      1. The lookup must be to the object that you will base the criteria on.
    2. A Formula Checkbox field must be created.
      1. This checkbox will contain the criteria for archiving the files.
      2. E.g. The formula in this use case would be: IF(Opportunity__r.stage = ‘Closed Won’, True, False).
    3. You must update the lookup field to contain the correct related records.
      1. This can be done by using workbench to get the related records.
      2. To get the related records you can use the following query:
        1. SELECT Id, LinkedEntityId, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN (SELECT Id FROM Opportunity)
        2. LinkedEntityId = The Id of the related parent record.
      3. Perform an update on the Content Versions by matching the ContentDocumentId and mapping the LinkedEntityId to the lookup field.
    4. To ensure that the lookup field populates in the future you must create a trigger.

    Creating the Archiver Policy

    • Select ContentDocuments as the object and configure the fields.

    Example Query: 

    SELECT Id FROM ContentDocument WHERE Id IN (SELECT ContentDocumentId FROM ContentVersion WHERE Formula_checkbox_API_Name = TRUE)

    « Previous ArticleNext Article »

    Contact Us

    Our Customer Support team is available by phone for urgent Production issues

    Standard Plan: Monday – Friday: 9:00 AM – 6:00 PM Local Business Hours

    Premier Plan: 24/7