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.
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