How to insert ContentDocument Using Apex in Salesforce

on

|

views

and

comments

Hi Everyone,

In this post, we will see how we can insert the Content Document or Content Version in Apex Test class.

Content Document: – Represents a document that has been uploaded to a library in Salesforce CRM Content or Salesforce Files.

Content Version: – Represents a specific version of a document in Salesforce CRM Content or Salesforce Files. One Content Document can have multiple content versions.

Content Document Link:- Represents the link between a Salesforce CRM Content document or Salesforce file and where it’s shared. A file can be shared with other users, groups, records, and Salesforce CRM Content libraries.

Files in Salesforce
Files in Salesforce

Here is the code for the test class.

ContentVersion – Contains the complete information about the Content Document. Which have the following field.

  1. Title – The title of a document.
  2. PathOnClient – The complete path of the document. One of the fields that determine the FileType.
  3. VersionData – The content of the file/document.
  4. Origin – The source of the content version. Valid values are:
  • C—A content document from the user’s personal library. The label is Content. The FirstPublishLocationId must be the user’s ID. If FirstPublishLocationId is left blank, it defaults to the user’s ID.
  • H—Salesforce files from the user’s My Files. The label is Chatter.

References

  1. https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentversion.htm
  2. https://testwebgrantha.xyz/sfdc/how-to-preview-files-in-lightning-community-using-lwc/
  3. https://testwebgrantha.xyz/sfdc/how-to-download-files-from-lightning-community-using-lwc/

Thanks for reading 🙂

#HappyReading #DeveloperGeeks #AskPanther #SFDCPanther

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to Utilize Salesforce CLI sf (v2)

The Salesforce CLI is not just a tool; it’s the cornerstone of development on the Salesforce Platform. It’s your go-to for building, testing, deploying, and more. As one of the most important development tools in our ecosystem

Save the day of a Developer with Apex Log Analyzer

Table of Contents What is Apex Log Analyzer? Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your...

Salesforce PodCast

Introduction Hey Everyone, Welcome to my podcast, the first-ever podcast in India for Salesforce professionals. Achievement We are happy to announce that we have been selected as Top...

Recent articles

More like this

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential