Loading

Mass Delete CMS Content from Enhanced CMS Workspaces for LWR Sites

Veröffentlichungsdatum: Oct 19, 2024
Beschreibung

In general, you do have an option to delete the CMS Content(ManagedContent) record from UI one at a time. However, if you have huge count of CMS records which you no longer need or in case you are looking to clean up some memory from your Org, deleting them one at a time from UI will prove to be a time-consuming task. 

In case you are looking to mass delete your managed Content records in one go from an Enhanced Workspace, we do have a way to do it via Apex code programmatically.

You can use CMS Connect API method for deletion i.e ConnectApi.ManagedContent.deleteManagedContentVariant(variantid) in your Apex code.

Note: Currently, mass deletion of CMS Records is NOT possible by exporting the records from ManagedContent or MangedContentVaraint Object in a .csv file and then deleting it on the basis of its record Ids. You'll end up getting insufficient rights error if you do so.

Lösung

You need to use ManagedContentVariant object to get rid of all ManagedContent Records. This object is available in API Version 61 or later.

Managed content variants are associated with a ManagedContent object. The managed content and variants are counted as one content record in your Salesforce org.

For example, say you have a managed content item of content type News and a default language of English. When you translate the News content into other languages such as Spanish, Japanese, and French, a managed content variant for each language is created.

When it comes to mass deletion, first of all you need to ensure all your CMS contents(variants) are in unpublished(Draft) Status. Also you need to be aware of the fact that you can't delete Language Content from a CMS Workspace, so all the CMS records that will be used in the SOQL query should not contain any Language content to avoid any exception/error during mass deletion. 

Below is the SOQL Query to get the list of all Draft contents without LanguageContent which will be used in your Apex Code:

SELECT Id,Name,ManagedContentId,ManagedContentKey,ManagedContentVariantStatus  from ManagedContentVariant where ManagedContentVariantStatus='Draft' AND Name NOT IN('LanguageContent')

Note: LanguageContent are out of the box CMS records created in the back end that controls the Language schema of your CMS Workspace and are Read-only.

Now please follow the steps for mass deletion:

  1. Open Developer Console and click on Debug-> Execute Anonymous Window
  2. Use the code below:

    List<ManagedContentVariant> accList = [SELECT Id,Name,ManagedContentId,ManagedContentKey,ManagedContentVariantStatus  from ManagedContentVariant where ManagedContentVariantStatus='Draft' AND Name NOT IN('LanguageContent')];

    System.debug(accList);// Iterate over the list and delete each ManagedContentVariant using the ConnectApi
    for (ManagedContentVariant variant : accList) {
        try {
            // Call the ConnectApi to delete each variant
            ConnectApi.ManagedContent.deleteManagedContentVariant(variant.Id);
            System.debug('Deleted ManagedContentVariant with Id: ' + variant.Id);
        } catch (Exception e) {
            // Handle any exceptions that occur during the delete operation
            System.debug('Failed to delete ManagedContentVariant with Id: ' + variant.Id + ' - ' + e.getMessage());
        }
    }

  3. Click on Execute.

    Note: The above query can be exceuted in any API Tool like Workbench which supports Apex execution and where you can invoke CMS Connect API from Apex.  
Nummer des Knowledge-Artikels

002954873

 
Laden
Salesforce Help | Article