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.
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:
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());
}
}
002954873

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.