1

I want to insert ContentVersion as a non-Admin Profile/User. When I run the code below I get the error below. I tried to clone the System Administrator profile and call it nonAdmin, that did not work. I gave all the related CRUD permissions to the user: ContentVersion, Document and ContentDocument, same error.

Code

system.runAs(nonAdmin){
    insert new ContentVersion(
        title=title, 
        pathOnClient=pathOnClient, 
        versionData=EncodingUtil.base64Decode(body));   
}

Error

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You do not have permission to upload files.: []

EDIT: Solution

It was a Trigger preventing the insertion.

2

FIELD_CUSTOM_VALIDATION_EXCEPTION implies there is either a custom validation rule on the object or trigger having some validation (using addError on the field) and this is not due to platform out of box error or a process stopping insertion of content object. To get it running look into the validation rules and create your test data so that it successfully bypasses the validation rule.

  • I have no validation rules on the ContentVersion object. And it works when I run it as an Admin. – Tredecies Oct 1 at 4:09
  • Other thing i can think of is a permission named "Select Files from Salesforce". Do you have this enabled or disabled on the profile ? – Mohith Shrivastava Oct 1 at 4:13
  • Thanks @mohith-shrivastava, it was a trigger preventing me from inserting. – Tredecies Oct 1 at 4:17
  • 1
    updated answer to be more precise with triggers also . – Mohith Shrivastava Oct 1 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.