Loading
Own from Salesforce
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Archive ContentDocuments Using Parent Object Filtering Criteria

          Archive ContentDocuments Using Parent Object Filtering Criteria

          Archive ContentDocument records using filtering criteria based on parent objects in the Archive managed package. For example, you can archive files associated with Opportunities when the opportunity stage is Closed Lost. You can use this business case to archive specific files while retaining essential Opportunity records in the system. This approach identifies duplicate records.

          Note
          Note This content relates to Archive. For Salesforce Archive, see Store Data Externally with Salesforce Archive.

          Key Concepts

          Before proceeding with archiving, it's essential to understand the distinction between ContentDocument and ContentVersion—two different objects in Salesforce:

          • ContentDocument: Created when a file is uploaded to Salesforce, reflecting the file’s relationship to the parent object.
          • ContentVersion: Represents the specific version of a document. For more details on ContentVersion, refer to this Salesforce knowledge article.

          Querying ContentVersions by Parent Record

          To retrieve a list of ContentDocument records linked to an Opportunity:

          SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink 
          WHERE LinkedEntityId IN (SELECT Id FROM Opportunity)

          You can then extract ContentVersion record IDs for the related ContentDocument.

          SELECT ContentDocumentId, Id FROM ContentVersion

          Configure Lookup Fields and Archiving Criteria

          Create lookup fields and apply archiving criteria to your Archive ContentDocuments in the Archive managed package.

          1. Create a lookup field on ContentVersion.

            You need to create a lookup field on the ContentVersion object that references the parent object used for filtering. For example, the field name can be ContentDocLookupOppty.

          2. Create a formula checkbox field.

            Next, create a formula checkbox on the ContentVersion object that contains the archiving criteria. For example, the checkbox could be called OpptyClosedLost with this formula.

            ISPICKVAL(ContentDocLookupOppty__r.StageName ,'Closed Lost')
          3. Update lookup field with related records.

            Use Salesforce Inspector, Workbench, or another third-party tool to update the lookup field with the correct related records. You can extract the related records with this query.

            SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink 
            WHERE LinkedEntityId IN (SELECT Id FROM Opportunity)

            LinkedEntityId: The ID of the related parent record.

          4. Perform data update.

            Match the ContentDocumentId with the corresponding LinkedEntityId and update the lookup field. Use a spreadsheet to help with this data update.

            • Copy-paste your ContentDocumentLink query results in the first tab, ContentDocumentLink. (Only in the highlighted columns.)
            • Copy-paste your ContentVersion query results in the second tab, ContentVersion. (Only in the highlighted columns.)
            • The third tab, ContentVersion_For_Upsert, is your output datasheet for upserting.

              You can download this specific sheet as a CSV file and import the records to your org. (Upsert - field mapping must include Id and ContentDocLookupOppty.)

          5. To ensure that the lookup field populates in the future, you must create a flow that forces the field to update going forward.

          To create the Archive 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)
           
          Loading
          Salesforce Help | Article