4

I am facing issues in deploying a change set. This contains one page and class. None of the components are new. There is a slight change in these two components.

When I deploy, an unrelated class fails with the following error:

System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.: [ContentWorkspaceId] Stack Trace: Class.TestManageContent_ContentVersionTrigger.testManageContentController: line 53, column 1

When I run only the test for the class it passes in Prod. It passes the Run All Test as well. Only during deployment, this blows up.

This class is unchanged for almost a year. This class is related to the Content, and I can confirm that I have the necessary access to the object and library used in the code. Also this test method has SeeAllData=true

Below is the code where the problem happens. If I run these lines of code in the Console, it creates the documents and links it to the Content Library. So it means my user has all the necessary rights. Only during deployment the exception happens.

ContentVersion testContentVersionA = new ContentVersion(Title='testContentA', ContentURL='http://google.com');
ContentVersion testContentVersionB = new ContentVersion(Title='testContentB', ContentURL='http://yahoo.com');

insert new ContentVersion[]{testContentVersionA, testContentVersionB};

ContentWorkspace testContentWorkspace = [select Id from ContentWorkspace where IsRestrictContentTypes=false and IsRestrictLinkedContentTypes=false limit 1];

ContentWorkspaceDoc cwdA = new ContentWorkspaceDoc(ContentWorkspaceId=testContentWorkspace.Id, ContentDocumentId=testContentVersionA.ContentDocumentId);
ContentWorkspaceDoc cwdB = new ContentWorkspaceDoc(ContentWorkspaceId=testContentWorkspace.Id, ContentDocumentId=testContentVersionB.ContentDocumentId);


insert new ContentWorkspaceDoc[]{cwdA, cwdB}; //Insufficient access comes here 

Any ideas as to what could be happening? Seems like a Salesforce bug, so I have raised a ticket anyway. If someone has seen this before let me know what can be done.

  • Have you included your profile in the change set? As the error says you do not have access to insert records in the ContentWorkspaceDoc. Are you system administrator? – Mihai Neagoe May 1 '15 at 8:17
  • Yes I am the system admin. And I have rights to create content. Running the test method individually clears the test. Only when deploying I get this. This class is not even in the change set. – AslamK May 1 '15 at 8:36
  • This could be due to sharing rules changing - is your class with or without sharing? Also it's a good idea to isolate the records by creating your own test data rather than "SeeAllData=true". I know it's annoying and long to create the records - but it's worth it. Take particular attention to owners, permissions, sharing rules - that error is almost invariably due to sharing rules (like you're updating an object which you are the owner, but it's referencing an Account that you don't, and some trigger is trying to update the account ... something like that) – Tammer Salem May 1 '15 at 10:05
  • @TammerSalem ContentWorkspaces is not possible to create in test methods. I have tried. Hence had to query existing records. salesforce.stackexchange.com/questions/23289/… – AslamK May 1 '15 at 11:56
  • 1
    Am simply offering up a solution that helps you resolve the issue that SeeAllData=true isn't a good way of testing your code consistently you can rely on to ensure your code can always be deployed. – crmprogdev May 1 '15 at 14:43

Your Answer

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

Browse other questions tagged or ask your own question.