Loading

Inserting a new ContentVersion via the API

Дата публикации: May 23, 2026
Описание

In Salesforce, files are managed through the ContentDocument and ContentVersion objects. A ContentDocument represents the file entity, while each revision of that file is stored as a separate ContentVersion record. When you need to upload a new version of an existing file using the Salesforce REST API, SOAP API, or Bulk API, you insert a new ContentVersion record linked to the existing ContentDocument. This is different from uploading a file for the first time, which requires a FirstPublishLocationId.

Решение

Required Fields for Inserting a New ContentVersion

When inserting a new version of an existing document via the API, include the following four required fields:

  1. ContentDocumentId — The Salesforce record ID of the existing ContentDocument that this version belongs to.
  2. ReasonForChange — A text description explaining why this new version is being uploaded (for example: "Updated contract pricing terms for Q2").
  3. PathOnClient — The filename or full file path on the client machine (for example: /documents/contract_v2.pdf). This value is used to determine the file extension and display name.
  4. VersionData — The base64-encoded binary content of the file being uploaded.

Note on FirstPublishLocationId

The FirstPublishLocationId field can only be set when inserting the very first version of a new document. Do not include this field when inserting a subsequent version of an existing ContentDocument — doing so will cause an error.

Номер статьи базы знаний

000385651

 
Загрузка
Salesforce Help | Article