2
votes

When using the Salesforce Partner API (version 21.0), how can I determine if the current user/session is able to create a new Content Version?

Using describeGlobal() I can confirm ContentVersion and ContentDocument are available as objects for the current organization.

Using describeSObject() I can confirm that the the current users session marks ContentVersion as createable. I've also confirmed that the fields I'm setting when inserting the ContentVersion record are marked as createable (PathOnClient, VersionData and FirstPublishedLocationId).

In my test cases, if the user has access to the Content area via the Salesforce web interface then the test case passes with the ContentVersion being created.

However, when I try the same code from a developer edition org (without access to the Content area) it falls over with the message:

FIELD_INTEGRITY_EXCEPTION - User doesn't have access to Salesforce Content. Invalid field value:: Content Origin

The createable Partner API metadata for ContentVersion and the fields indicated that this should have worked.

I'm working in C#, but the Java code in recipe Publishing Documents Into a Salesforce CRM Content Personal Workspace is doing much the same thing without the creatable metadata checks.

To try and rule out my code as the cause of the issue I've confirmed that the ContentVersion should be createable using Force.com Explorer:

Force.com Explorer showing attributes for ContentVersion

2
I've asked the same question on the Salesforce Developer forums boards.developerforce.com/t5/NET-Development/…Daniel Ballinger

2 Answers

2
votes

The Content objects are a little funky in Salesforce, as they were part of an acquisition of a company called Koral, so some of their behaviors aren't exactly the same as other standard Salesforce objects.

I've tried checking ContentDocument.creatable, but this is false even for users who can otherwise create Content.

This is because ContentDocument is never creatable, it only supports the following methods: delete(), query(), retrieve(), undelete(), describeSObjects()

To create a ContentDocument, you need to create a new ContentVersion object without setting the ContentDocumentId.

From the Web Services API Developer's Guide:

This automatically creates a parent document record. When adding a new version of the document, you must specify an existing ContentDocumentId which initiates the revision process for the document. When the latest version is published, the title, owner, and publish status fields are updated in the document.

Checking for ContentVersion.creatable should work.

2
votes

I think I've figured it out. Checking that ContentVersion is creatable alone is not sufficient.

I also needed to check that the current user (as indicated by getUserInfo()) has the field UserPermissionsSFContentUser and that it is true.

From the Web Services API Developer's Guide for User.UserPermissionsSFContentUser.

Indicates whether the user is allocated one Salesforce CRM Content User License (true) or not (false). Label is Salesforce CRM User. The Salesforce CRM Content User license grants the user access to the Salesforce CRM Content application.