0
1

More than 1 year has passed since last update.

商談でアップロードしたファイル(PDF、エクセルなど)を自動的に指定ライブラリに格納する方法

Posted at

元の質問

以下のようなコードで可能かと思う。

trigger createContentDocumentLink on ContentDocument (After insert,after update ,after delete) {
    
    Set<Id> ContentDocumentIdSet = new Set<Id>();  
    if (Trigger.isInsert || Trigger.isUpdate) {
        for (ContentDocument cd : Trigger.new){
            ContentDocumentIdSet.Add(cd.Id);
        }
    }
    
    //if (Trigger.isDelete || Trigger.isUpdate) {
    //    for (ContentDocument cd : Trigger.old){
    //        ContentDocumentIdSet.Add(cd.Id);
    //    }
    //}
    
    List<ContentDocumentLink> cdlList = [SELECT Id,ContentDocumentId,LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId =: ContentDocumentIdSet];
    
    List<ContentWorkspaceDoc> insert_cwkList = new List<ContentWorkspaceDoc>();
    for (ContentDocumentLink cdl : cdlList){
        String LinkedEntityId = cdl.LinkedEntityId;
        if (LinkedEntityId.left(3) == '006'){
            //ここで ContentWorkspaceDocを割り振るロジックが必要です。
            ContentWorkspaceDoc cwk = new ContentWorkspaceDoc();
            cwk.ContentDocumentId = cdl.ContentDocumentId;
            cwk.ContentWorkspaceId = 'x123456789012345678';//最終的にIdをセットできればいいと思います。
            insert_cwkList.add(cwk);
        }
    }
    if (insert_cwkList.size() > 0) insert insert_cwkList;

}
0
1
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
1