3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Salesforce】Apexでファイルをライブラリ経由して公開方法

Last updated at Posted at 2020-03-17
Page 1 of 7

Apexでファイルをライブラリ経由して公開方法

概要図

image.png


ファイルの登録

 ContentDocument直接書き込みできないので、ContentVersionにレコードを登録して、ContentDocumentにデータを自動登録できる。

getAlertDescriptionFile
    public static ContentVersion getAlertDescriptionFile() {
        ContentVersion contentVersion_1 = new ContentVersion(
            Title = "Test",
            PathOnClient = 'Penguins.jpg',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true
        );
        return contentVersion_1;
    }

ライブラリを作成

getContentworkspace
    public static Contentworkspace getContentworkspace() {

        return new Contentworkspace(
            name='test for share file with library'
        );
    }

ファイルをライブラリに格納

getContentWorkspaceDoc
    public static ContentWorkspaceDoc getContentWorkspaceDoc(ContentDocument cd, ContentWorkspace cws) {

        return new ContentWorkspaceDoc(
            contentdocumentId = cd.id,
            ContentWorkspaceId = cws.id
        );
    }

ライブラリ権限の作成

getContentWorkspacePermission
    public static ContentWorkspacePermission getContentWorkspacePermission() {

        return new ContentWorkspacePermission(
            Name='test view',
            PermissionsAddContent = true,
            PermissionsTagContent = true
        );
    }

ライブラリと権限とユーザに割り当て

getContentWorkspaceMember
    public static ContentWorkspaceMember getContentWorkspaceMember(ContentWorkspace cws, ContentWorkspacePermission cwsp, User usr) {

        return new ContentWorkspaceMember(
            ContentWorkspaceId = cws.id,
            ContentWorkspacePermissionId = cwsp.id,
            MemberId = usr.id
        );
    }
3
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?