开发者

Programatically add/publish a record to the workspace/libraries in salsforce using apex

开发者 https://www.devze.com 2023-03-17 06:24 出处:网络
I have created a custom visualforce page. Here in the controller class i allow the user to create folders.

I have created a custom visualforce page. Here in the controller class i allow the user to create folders.

I want when user clicks OK (a custom button) then the new folder is published as a record in the workspace but i cannot find how to do it.

开发者_运维问答

Any help is appreciated.


Finally i achieved a way to publish a record to shared workspace:

        ContentVersion doc = new ContentVersion();
        string before = 'Testing base 64 encode'; 
        Blob beforeblob = Blob.valueOf(before);
        doc.Title = title;
        doc.PathOnClient = 'xyz';
        doc.VersionData = beforeblob;
        insert doc;

        doc = [select ContentDocumentId from ContentVersion where id = :doc.id];
        ContentWorkspace shareWorkspace = [select id from ContentWorkspace 
                  where name = :workspaceName limit 1];

        ContentWorkspaceDoc docLink = new ContentWorkspaceDoc();
        docLink.ContentDocumentId = doc.ContentDocumentId;
        docLink.ContentWorkspaceId = shareWorkspace.id;
        insert docLink;

Publish Record to Personal Workspace:

        ContentVersion doc = new ContentVersion();
        string before = 'Testing base 64 encode'; 
        Blob beforeblob = Blob.valueOf(before);
        doc.Title = title;
        doc.PathOnClient = title;
        doc.VersionData = beforeblob;
        **doc.FirstPublishLocationID = UserInfo.getUserId();**
        insert doc; 

I have created a blob from String but i need to create a blob that can show a table with all the info that i want to display like size & author name.

Thanks Paul for the idea. May be someone can help me in creating blob of my choice.

:)


Swati

You need to create the Folder and then after inserting the Folder create a ContentWorkspaceDoc record linking the two. You can find the api reference to the object here. This should then allow you to setup the linking you require.

Paul

0

精彩评论

暂无评论...
验证码 换一张
取 消