LoginSignup
0
0

添付ファイル関係 ContentDocument

Last updated at Posted at 2022-05-09

まとめページに戻る
まとめA~M

探すと面倒なので、関連する情報をまとめておきたいと思います。

オブジェクトの説明

ContentVersion

CombinedAttachment
CombinedAttachment フィールド定義
この読み取り専用オブジェクトには、すべてのメモ、添付ファイル、Googleドキュメント、Salesforce CRMコンテンツのライブラリにアップロードされたドキュメント、およびレコードに関連付けられたChatterに追加されたファイルが含まれます。

ContentDocument
Salesforce CRM Content のライブラリにアップロードされたドキュメントまたは Salesforce Files を表します。Salesforce CRM Content では、バージョン 17.0 以降でこのオブジェクトを使用できます。Salesforce Files では、API バージョン 21.0 以降でこのオブジェクトを使用できます。
公開できる最大ドキュメント数は 30,000,000 です。アーカイブされたファイルは、この制限とディスク使用量制限に含まれます。
Contact Manager Edition、Group Edition、Professional Edition、Enterprise Edition、Unlimited Edition、および Performance Edition を使用するお客様は、24 時間につき最大ですべての Sandbox 組織を含み 200,000 件の新しいバージョンを公開できます。
Developer Edition とトライアル版のお客様は、24 時間につき最大で 2,500 件の新しいバージョンを公開できます。

ContentDocumentLink

  • ContentDocumentLink に対する条件なしでは、クエリを実行することはできません。
  • ContentDocumentId で条件検索している場合は、ContentDocument 項目で条件検索することはできません。LinkedEntityId で条件検索している場合は、ContentDocument 項目でのみ条件検索を実行できます。
  • 関連オブジェクト項目で条件検索することはできません。たとえば、ファイルのリンク先の取引先のプロパティで条件検索をすることはできません。タイトル項目などのファイルのプロパティでは検索条件できます。
  • SOQL クエリの絞り込みでは、Id、ContentDocumentId、LinkedEntityId のいずれかを条件にする必要があります。
  • ContentDocumentLink オブジェクトでは、挿入、更新、削除操作の前後のトリガがサポートされます。ContentDocumentLink トリガは、ContentDocumentLink に追加や削除があるたびに実行されます。ファイルが削除されると、ContentDocument の削除トリガが実行されますが、カスケードされた ContentDocumentLink の削除では ContentDocumentLink トリガは実行されません。

image.png

image.png

image.png

client mentioned that they have another package conflicting with CMTD

Apexでの操作

ContentVersion オブジェクトにUpdate操作をしていますか? 私自身は今までInsertしかしてこなかったのであんまり深く考えたことはなかったのですが、Updateはできないと思います。

以下の説明にあるように、 ContentVersion オブジェクト をinsertするときに同じ ContentDocumentId をセットすることでバージョン管理ができると思います。

You can also create a ContentVersion record and have the same ContentDocumentId so that it becomes different versions of same content and the version history will be automatically maintained.

https://salesforce.stackexchange.com/questions/733/isnt-contentversion-versiondata-updateable-amendable

このような感じでバージョン管理してますね。

if (cv.ContentDocumentId == null) { 
// ※新規に作成されたContentDocumentがない場合、新たにContentDocumentが作成されるのでContentDocumentLinkを作る。
    String id_val = targetIds.get(i);
    ContentDocumentLink cdl = new ContentDocumentLink(); // ファイルとオブジェクトへのリンク
    cdl.LinkedEntityId = id_val;
    cdl.ShareType = 'V';
    ContentVersion cv2 = cvMap.get(cv.Id);
    Id cdId = cv2.ContentDocumentId;
    cdl.ContentDocumentId = cdId;
    cdlinkList.add(cdl);
}

以下の設定がありますが、オブジェクトを選択はできないと思います。すべてのオブジェクトで添付できなくなると思います。

権限セットを使用して、ユーザが投稿、レコード、および他のオブジェクトに Salesforce ファイルを添付することを防止します。

ユーザによる Salesforce ファイル添付の防止
https://help.salesforce.com/s/articleView?id=sf.admin_files_sfs_perm.htm&type=5

Apexトリガーを使えばできそうな感じです。

https://salesforce.stackexchange.com/questions/288989/is-there-any-way-to-prevent-upload-a-file-in-notes-attachment-for-a-custom-obj

Aura コンポーネントの部品

アップロード・ダウンロード関係

共有設定

Lightningではオプションがないと書かれていますね。
全ての内部ユーザを含んだ公開グループを作って、そのグループをセットするのが早いかもしれません。

To extend or set file access to the company:

  1. Share the file with a Public Group that has all internal users in it
  2. Share the file via the All Company Feed on Chatter tab
  3. Extend Access to "Any user in your company" via Classic

File sharing setting for 'Any User in your company' is not available in Lightning

Apex トリガーで実装する例が紹介されています。

To customize file sharing behavior, define an Apex trigger for the ContentDistribution or ContentDocumentLink objects. The ContentDistribution object represents a file shared externally. A ContentDocumentLink represents a file shared with an internal object, such as a user, group, or record.

The ContentDocumentLink object supports triggers before and after these operations: insert, update, delete.

https://salesforce.stackexchange.com/questions/127195/how-to-share-the-uploaded-salesforce-file-automatically

画面関係

関連資料

This List is not customizable

image.png

できないこと

以下の答えは「それはできません」です。

https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A90S2SAJ

アイデアや回避策が提案されていますが、場合によっては機能しないようです。

https://ideas.salesforce.com/s/idea/a0B8W00000GdgbGUAR/make-some-content-preview-only-no-download

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0