ContentVersion

Represents a specific version of a document in Salesforce CRM Content or Salesforce Files. This object is available in versions 17.0 and later for Salesforce CRM Content documents. This object is available in versions 20.0 and later for Salesforce Files.

The maximum number of versions that can be published in a 24-hour period is 200,000.

Note: Depending on how files are shared, queries on ContentDocument and ContentVersion without specifying an ID won't return all files a user has access to. For example, if a user only has access to a file because they have access to a record that the file is shared with, the file won't be returned in a query such as "SELECT Id FROM ContentDocument."

Supported Calls

create(), describeLayout(), describeSObjects(), query(), retrieve(), search(), update(), upsert()

Special Access Rules

Fields

Field Details
Checksum
Type
string
Properties
Filter, Group, Nillable, Sort
Description
MD5 checksum for the file.
ContentBodyId
Type
reference
Properties
Create, Filter, Group, Nillable, Sort
Description
Allows inserting a file version independently of the file blob being uploaded. This field is available for query and insert only. It can only point to a ContentBody record. This field is available in API version 40.0 and later.
ContentDocumentId
Type
reference
Properties
Create, Filter, Group, Sort
Description
ID of the document.
ContentLocation
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort
Description
Origin of the document. Valid values are:
  • S—Document is located within Salesforce. Label is Salesforce.
  • E—Document is located outside of Salesforce. Label is External.
  • L—Document is located on a social network and accessed via Social Customer Service. Label is Social Customer Service.
ContentModifiedById
Type
reference
Properties
Filter, Group, Nillable, Sort
Description
ID of the user who modified the document.
ContentModifiedDate
Type
dateTime
Properties
Create, Filter, Nillable, Sort
Description

Date the document was modified.

ContentModifiedDate updates when, for example, the document is renamed or a new document version is uploaded. When uploading the first version of a document, ContentModifiedDate can be set to the current time or any time in the past.

ContentSize
Type
int
Properties
Filter, Group, Nillable, Sort
Description
Size of the document in bytes. Always zero for links.
ContentUrl
Type
url
Properties
Create, Filter, Group, Nillable, Sort, Update
Description
URL for links. This is only set for links. One of the fields that determines the FileType. The character limit in API versions 43.0 and later is 1,300. The character limit in API versions 32.0 and earlier was 255.
Description
Type
textarea
Properties
Create, Filter, Nillable, Sort, Update
Description
Description of the content version.
Division
Type
picklist
Properties
Defaulted on create, Filter, Group, Restricted picklist, Sort
Description
A logical segment of your organization's data. For example, if your company is organized into different business units, you could create a division for each business unit, such as “North America,” “Healthcare,” or “Consulting.” Available only if the organization has the Division permission enabled.
ExternalDataSourceId
Type
reference
Properties
Create, Filter, Group, Nillable, Sort, Update
Description
ID of the external document referenced in the ExternalDataSource object.
ExternalDocumentInfo1
Type
string
Properties
Create, Filter, Nillable, Sort, Update
Description
Stores the URL of the file in the external content repository. The integration from the external source determines the content for this string. After the reference or copy is created, the URL of the external file is updated when you:
  • Republish a file reference in Lightning Experience
  • Open the document
  • Create a file reference in the Chatter REST API with reuseReference set to true.
When the file is updated, the shared link is updated to the most current version.
ExternalDocumentInfo2
Type
string
Properties
Create, Filter, Nillable, Sort, Update
Description
Contains the external file ID. Salesforce determines the content for this string, which is private. The content can change without notice, depending on the external system. After the file reference is created, this field isn’t updated, even if the file path changes.
FeaturedContentBoost
Type
int
Properties
Filter, Group, Nillable, Sort
Description
Read only. Designates a document as featured.
FeaturedContentDate
Type
date
Properties
Filter, Group, Nillable, Sort
Description
Date the document was featured.
FileExtension
Type
string
Properties
Filter, Group, Nillable, Sort
Description

File extension of the document.

This field is available in API version 31.0 and later.

FileType
Type
string
Properties
Filter, Group, Sort
Description
Type of content determined by ContentUrl for links or PathOnClient for documents.
FirstPublishLocationId
Type
reference
Properties
Create, Filter, Group, Nillable, Sort
Description

ID of the location where the version was first published. If the version is first published into a user's personal library or My Files, the field will contain the ID of the user who owns the personal library or My Files. If the first version is published into a public library, the field will contain the ID of that library.

Accepts all record IDs supported by ContentDocumentLink (anything a file can be attached to, like records and groups).

Setting FirstPublishLocationId allows you to create a file and share it with an initial record/group in a single transaction, and have the option to create more links to share the file with other records or groups later. When a file is created, it’s automatically linked to the record, and PublishStatus will change to Public from Pending/Personal.

This field is only set the first time a version is published via the API. FirstPublishLocationId can’t be set to another ID when a new content version is inserted.

IsAssetEnabled
Type
boolean
Properties
Create, Group, Defaulted on create
Description
Can be specified on insert of ContentVersion to automatically convert a ContentDocument file into a ContentAsset. This field can be SOQL queried, but it can’t be edited. This field is available in API version 38.0 and later.
IsEncrypted
Note

Note

This information is about Shield Platform Encryption and not Classic Encryption.

Type
boolean
Properties
Defaulted on create, Filter, Group, Sort
Description
Indicates whether files are encrypted using Shield Platform Encryption (true) or not (false). This field is available in API version 34.0 and later.
IsLatest
Type
boolean
Properties
Defaulted on create, Filter, Group, Sort
Description
Indicates whether this is the latest version of the document (true) or not (false).
IsMajorVersion
Type
boolean
Properties
Create, Defaulted on create, Filter, Group, Sort
Description
true if the document is a major version; false if the document is a minor version. Major versions can’t be replaced.
Language
Type
picklist
Properties
Create, Filter, Nillable, Restricted picklist, Update
Description
The language for this document. This field defaults to the user's language unless the organization is multi-language enabled.

Specifies the language of the labels returned. The value must be a valid user locale (language and country), such as de_DE or en_GB. For more information on locales, see the Language field on the CategoryNodeLocalization object.

NegativeRatingCount
Type
int
Properties
Filter, Group, Nillable, Sort
Description
Read only. The number of times different users have given the document a thumbs down.

Rating counts for the latest version are not version-specific. If Version 1 receives 10 thumbs-down votes, and Version 2 receives 2 thumbs-down votes, the NegativeRatingCount on Version 2 is 12. However, rating counts are not retroactive for prior versions. The NegativeRatingCount on Version 1 is 10.

NetworkId
Type
reference
Properties
Create, Filter, Group, Nillable, Sort
Description
ID of the community that this file originated from. This field is available in API version 26.0 and later, if Salesforce Communities is enabled for your organization.

You can only add a NetworkId when creating a file. You can’t change or add a NetworkId for an existing file.

Origin
Type
picklist
Properties
Create, Defaulted on create, Filter, Group, Restricted picklist, Sort
Description
The source of the content version. Valid values are:
  • C—Content document from the user's personal library. 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 file from the user's My Files. Label is Chatter. The FirstPublishLocationId must be the user's ID. If FirstPublishLocationId is left blank, it defaults to the user's ID. Origin can only be set to H if Chatter is enabled for your organization.
This field defaults to C. Label is Content Origin.
OwnerId
Type
reference
Properties
Create, Defaulted on create, Filter, Group, Sort, Update
Description
ID of the owner of this document.
PathOnClient
Type
string
Properties
Create, Filter, Nillable, Sort
Description
The complete path of the document. One of the fields that determines the FileType.
Note

Note

Specify a complete path including the path extension in order for the document to be visible in the Preview tab.

PositiveRatingCount
Type
int
Properties
Filter, Group, Nillable, Sort
Description
Read only. The number of times different users have given the document a thumbs up.

Rating counts for the latest version are not version-specific. If Version 1 receives 10 thumbs-up votes, and Version 2 receives 2 thumbs-up votes, the PositiveRatingCount on Version 2 is 12. However, rating counts are not retroactive for prior versions. The PositiveRatingCount on Version 1 is 10.

PublishStatus
Type
picklist
Properties
Defaulted on create, Filter, Group, Restricted picklist, Sort
Description
Indicates if and how the document is published. Valid values are:
  • P—The document is published to a public library and is visible to other users. Label is Public.
  • R—The document is published to a personal library and is not visible to other users. Label is Personal Library.
  • U—The document is not published because publishing was interrupted. Label is Upload Interrupted.
RatingCount
Type
int
Properties
Filter, Group, Nillable, Sort
Description
Read only. Total number of positive and negative ratings.
ReasonForChange
Type
string
Properties
Create, Filter, Nillable, Sort, Update
Description
The reason why the document was changed. This field can only be set when inserting a new version (revising) a document.
RecordTypeId
Type
reference
Properties
Create, Filter, Nillable, Update
Description
ID of the record type of the version.
Custom fields are restricted in RecordTypeId. When an administrator creates a custom field via the API it must be added to at least one page layout:
  • If the custom field is added to the page layout associated with the General record type, the RecordTypeId that corresponds to that record type does not have to be set on the version record.
  • If the custom field is added to the page layout associated with a custom record type, the RecordTypeId that corresponds to that record type must be set on the version record.
SharingOption
Type
picklist
Properties
Create, Defaulted on create, Filter, Group, Restricted picklist, Sort, Update
Description
Controls whether sharing is frozen for a file. Only administrators and file owners with Collaborator access to the file can modify this field. Default is Allowed, which means that new shares are allowed. When set to Restricted, new shares are prevented without affecting existing shares.

This field is available in API versions 35.0 and later.

SharingPrivacy
Type
picklist
Properties
Create, Defaulted on create, Filter, Group, Restricted picklist, Sort, Update
Description
Controls sharing privacy for a file. Only administrators and file owners with Collaborator access to the file can modify this field. Default is Visible to Anyone With Record Access. When set to Private on Records, the file is private on records but can be shared selectively with others.

This field is available in API versions 41.0 and later.

TagCsv
Type
textarea
Properties
Create, Nillable, Sort, Update
Description
Text used to apply tags to a content version via the API.
TextPreview
Type
string
Properties
Nillable, Filter,Group, Sort
Description
A preview of a document. Available in API version 35.0 and later.
Title
Type
string
Properties
Create, Filter, Group, Sort, Update
Description

The title of a document.

VersionData
Type
base64
Properties
Create, Nillable, Update
Description
The content or body of the note, which can include properly formatted HTML or plain text. When a document is uploaded or downloaded via the API, it should be base64 encoded (for upload) or decoded (for download). Any special characters within plain text in the Content field must be escaped. You can escape special characters by calling content.escapeHtml4().
This field can't be set for links.

The maximum file size you can upload via the SOAP API is 50 MB. When a document is uploaded or downloaded via the API, it is converted to base64 and stored in VersionData. This conversion increases the document size by approximately 37%. Account for the base64 conversion increase so that the file you plan to upload is less than 50 MB after conversion.

If a custom Apex download handler is active, this field is accessed from the API, and the download is not allowed, Salesforce will return a CONTENT_CUSTOMIZED_DOWNLOAD_EXCEPTION error.
VersionNumber
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The version number. The number increments with each version of the document, for example, 1, 2, 3.

Usage

Applying Tags to ContentVersion Records

Tags can be applied to ContentVersion records using either Enterprise or Partner API.

To apply tags to a ContentVersion record, set a value in the TagCsv field. For example, setting this field to one,two,three creates and associates three tags to that version.

To delete tags from a ContentVersion record, perform a standard API update, and remove any values from the TagCsv field that you want to delete. For example, if the original TagCsv is one,two,three, perform an API update specifying one,three in the TagCsv field to delete two. To delete all tags from a ContentVersion you perform a standard API update by setting the field to null.

If you create a ContentVersion record and want to revise it via the API, you insert another ContentVersion record but associate it to the same ContentDocument record as the original. This has an impact on tagging:
  • If you insert the revision and do not set any value in the TagCsv field, any tags applied to the previous version are automatically applied to the new version.
  • If you insert the revision and specify a new TagCsv field, no tags transfer over and the tags you specify are applied instead.

When you perform a SOQL query for a ContentVersion record and select the TagCsv field, all the tags associated with that record are returned. The tags in the string are always ordered alphabetically even if they were inserted in a different order. You can't use the TagCsv field as part of a filter in a SOQL query. You can't query all tags in your organization.

Library tagging rules:

See Also