how to create content in a folder salesforce apex
How to Insert files using Salesforce Apex
Salesforce Introduced the Salesforce Files feature as a part of Winter'16 and the salesforce file is going to replace Notes & Attachment.
Salesforce Files stored now instead of Attachment to Salesforce File Object called "ContentVersion".
Salesforce Files in Lightning Experience:

How To Enable to Salesforce Files:
From Setup -> Salesforce Files -> Enable "Files uploaded to the Attachments related list on records are uploaded as Salesforce Files, not as attachments"
Example to Insert Salesforce Files using Apex Class:
String yourFilesContent = 'TheBlogReaders.com File upload content'; ContentVersion conVer = new ContentVersion(); conVer.ContentLocation = 'S'; // to use S specify this document is in Salesforce, to use E for external files conVer.PathOnClient = 'testing.txt'; // The files name, extension is very important here which will help the file in preview. conVer.Title = 'Testing Files'; // Display name of the files conVer.VersionData = EncodingUtil.base64Decode(yourFilesContent); // converting your binary string to Blog insert conVer; //Insert ContentVersion // First get the Content Document Id from ContentVersion Object Id conDoc = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId; //create ContentDocumentLink record ContentDocumentLink conDocLink = New ContentDocumentLink(); conDocLink.LinkedEntityId = '0066F00000qNVUv'; // Specify RECORD ID here i.e Any Object ID (Standard Object/Custom Object) conDocLink.ContentDocumentId = conDoc; //ContentDocumentId Id from ContentVersion conDocLink.shareType = 'V'; insert conDocLink;
Here ShareType is either V, C and I
V = Viewer permission. The user can explicitly view but not edit the shared file.
C = Collaborator permission. The user can explicitly view and edit the shared file.
I = Inferred permission. The user's permission is determined by the related record. For shares with a library, this is defined by the permissions the user has in that library. Inferred permission on shares with libraries and file owners is available in API versions 21.0 and later. Inferred permission on shares with standard objects is available in API versions 36.0 and later.
- Overview of Salesforce Files
- Trailhead Module for Work with Notes and Files
- Example to Insert Content Note Using Salesforce Apex Class – http://theblogreaders.com/capture-parentid-contentnote-salesforce/
- Convert Attachments to Files using Magic Mover for Notes and Attachments to Lightning Experience on AppExchange
- Comparing Files and Attachments features
- Differences Between Files, Salesforce CRM Content, Salesforce Knowledge, Documents, and Attachments
- Migrate notes and attachments to Lightning
Post Views: 34,592
how to create content in a folder salesforce apex
Source: http://theblogreaders.com/insert-files-using-salesforce-apex/
Posted by: browncorgentor.blogspot.com

0 Response to "how to create content in a folder salesforce apex"
Post a Comment