Understanding the INVALID_STATUS Error
This error occurs when attempting to set VersionData
on a ContentVersion record while IsMajorVersion
is set to true. Salesforce prevents this combination because major versions should reference existing content rather than creating new binary data.
Causes of the INVALID_STATUS Error
The most common causes of this error include:
- Setting both
VersionData
andIsMajorVersion = true
simultaneously on ContentVersion - Attempting to upload new file content while marking it as a major version
- Incorrect API usage when creating document versions programmatically
- Misunderstanding the difference between major and minor version workflows
How to Handle the INVALID_STATUS Error
To resolve this error, choose one of these approaches:
Option 1: Create Minor Version with New Content
apexContentVersion cv = new ContentVersion(); cv.Title = 'Document Title'; cv.PathOnClient = 'filename.pdf'; cv.VersionData = Blob.valueOf('file content'); cv.IsMajorVersion = false; // Set to false for new content insert cv;
Option 2: Create Major Version Without New Content
apexContentVersion cv = new ContentVersion(); cv.Title = 'Document Title'; cv.ContentDocumentId = existingDocumentId; cv.IsMajorVersion = true; // Only when not setting VersionData // Do not set VersionData for major versions insert cv;
Option 3: Update Existing Version to Major First create the version, then update the major version flag separately if needed through the UI or appropriate API calls.
Conclusion
This error enforces Salesforce's content versioning rules where major versions cannot include new binary data. Always set IsMajorVersion = false
when uploading new content, or omit VersionData
when creating major version references.