一般的に、CMS コンテンツ (ManagedContent) レコードは、UI から 1 件ずつ削除することができます。しかし、不要になった大量の CMS レコードがある場合や、組織のメモリを整理したい場合、UI から 1 件ずつ削除する方法では非常に時間がかかります。
管理コンテンツレコードを拡張ワークスペースから一括削除しようする場合は、Apex コードを使用してプログラムで実行する方法があります。
削除には CMS Connect API のメソッド、つまり、Apex コード内 でConnectApi.ManagedContent.deleteManagedContentVariant(variantid) を使用できます。
注意: 現在、ManagedContent や MangedContentVaraint オブジェクトからレコードを .csv ファイルにエクスポートし、レコード ID に基づいて削除する方法で CMS レコードを一括削除することはできません。これを行うと、権限不足エラーが発生します。
すべての ManagedContent レコードを削除するには、ManagedContentVariant オブジェクトを使用する必要があります。このオブジェクトは、API バージョン 61 以降で使用できます。
管理コンテンツバリアントは、ManagedContent オブジェクトに関連付けられています。管理コンテンツとバリアントは、Salesforce 組織内で 1 つのコンテンツレコードとしてカウントされます。
たとえば、コンテンツタイプがニュースでデフォルト言語が英語の管理コンテンツアイテムがあるとします。このニュースコンテンツをスペイン語、日本語、フランス語などの他の言語に翻訳すると、各言語の管理コンテンツバリアントが作成されます。
一括削除を行う場合、まずすべての CMS コンテンツ (バリアント) が未公開 (ドラフト) ステータスであることを確認する必要があります。また、CMS ワークスペースから言語コンテンツを削除することはできないため、一括削除中に例外やエラーが発生しないよう、SOQL クエリで使用するすべての CMS レコードに言語コンテンツが含まれないようにする必要があります。
以下は、Apex コードで使用される、LanguageContent のないすべてのドラフトコンテンツのリストを取得するためのSOQL クエリです。
SELECT Id,Name,ManagedContentId,ManagedContentKey,ManagedContentVariantStatus from ManagedContentVariant where ManagedContentVariantStatus='Draft' AND Name NOT IN('LanguageContent')
注意: LanguageContent は、バックエンドで作成されるすぐに使用できる CMS レコードです。CMS ワークスペースの言語スキーマを制御し、読み取り専用です。
以下の一括削除の手順に従ってください。
List<ManagedContentVariant> accList = [SELECT Id,Name,ManagedContentId,ManagedContentKey,ManagedContentVariantStatus from ManagedContentVariant where ManagedContentVariantStatus='Draft' AND Name NOT IN('LanguageContent')];
System.debug(accList);// リストを反復処理し、ConnectApi を使用して各 ManagedContentVariant を削除する
for (ManagedContentVariant variant : accList) {
try {
// ConnectApi を呼び出して各バリアントを削除する
ConnectApi.ManagedContent.deleteManagedContentVariant(variant.Id);
System.debug('Deleted ManagedContentVariant with Id: ' + variant.Id);
} catch (Exception e) {
// 削除操作の間に発生する例外を処理する
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.