9

After the summer 13 update. I can no longer have statements like this in my test methods:

Case c1 = new Case();
c1 = CreateCase('00530000003sMR5','Low','New','Test Case2','Calling Create Case','TEST');

   public static Case createCase(string inputOwnerID,string inputPriority,string inputStatus, string inputSubject, string inputDescription, string Branch) {
           Case c = new Case(
                OwnerId = inputOwnerID, //assigning ownerId from parameter
                Priority = inputPriority, //assigning case Priority from parameter 
                Status = inputStatus, //assigning case Status from parameter
                Subject = inputSubject, //assigning case subject from parameter
                Description = inputDescription, //case description
                SS_Department__c = 'IT', //Department
                ContactId = '0033000000qYHOw', // case contact 
                SS_Software_Request_Type__c = 'Maintenance', //software request type
                SS_Requested_Completion_Date__c = Date.today() + 15, //requested completion date
                SFDC_User_License_Used__c = '00530000003sMR5',
                SS_Software_Affected__c = 'Email', //software affected
                SS_Portal_Branch__c = Branch,
                RecordTypeId = '01230000000sMUX' //case record type
                );

The same statements used to work before, but I am now making changes to some classes and I get these error messages. No idea why, because nothing has changed that would affect permissions etc on my side.

System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: 0044000000qJTQr: []

Any ideas?

4
  • 2
    What's the hardcoded ID that you're using? You should never use hardcoded IDs in code or tests!
    – Matt Lacey
    Commented Jun 13, 2013 at 0:35
  • @LaceySnr that ID is the ID of the original case owner. Do you think that is causing the problem? Strange that it worked before though
    – user988
    Commented Jun 13, 2013 at 0:53
  • 1
    It shouldn't have changed, but you shouldn't depend on data that's in the system already. Insert a new user in the test and use that user as the owner of the case. I've blogged about test methods a couple of times recently: laceysnr.com/2013/06/smartfactory-easier-salesforce-test.html I can't say why something has changed but I suspect that is it.
    – Matt Lacey
    Commented Jun 13, 2013 at 0:56
  • Can you post the relevant body of your CreateCase method? I'd especially like to know whether there's a record type being set (maybe somebody took the right to use this rec. type from SysAdmins). Failing that - any new case assignment rules, workflows related to Owner field etc?
    – eyescream
    Commented Jun 13, 2013 at 6:25

4 Answers 4

12

You seem to have a lot of hard coded Ids in your test method which isn't best practice in Salesforce Test Methods. Your issue could be because your test method cannot access data in your org or it could be a security issue.

I would suggest checking the following:

  1. Record Type Id specified is valid for your profile
  2. You have create permission on Case object
  3. You have read permission on Contact (specifically record '0033000000qYHOw')
  4. User '00530000003sMR5' is active
  5. Check your API Version is less than version 24.0. Later API versions will not give you access to org data by default. Consider creating records in the test method, or use annotation @isTest(SeeAllData=true) at the top of your test class.
3

(continuing from comments)

So there's a record type being set on your Case. Can you check your Profile (or Profile of the user in runAs if you use it in the test) for allowed Case record types and double check that the Rec type you use is available? If it's not available - yep, that's the error you'll be getting.

It's not a Spring'13-related thing, somebody had to recently modify your Profile (use Setup Audit Trail to track them and start shouting ;)).

(You can also temporarily comment out the line with rec. type setting and check if the test succesfully inserts. It might die somewhere later depending on your logic but by commenting the lookups out you should eventually nail it).


Although I have to say I don't recognize what object could be under 004 prefix. And this piece of code gives up (did you do some anonymisation?):

Id i = '0044000000qJTQr';
System.debug(i.getsobjecttype());
0

try checking the following
1)Check that the running user (in this case you) has access to the object being operated. Check that he has CREATE privileges on the object.
2)Check that the Owner ie User with id '00530000003sMR5' has CREATE permission on the object. Check that his profile has the CREATE permission on the particular object.

I found a very good article on this error at http://www.forcetree.com/2011/12/insufficientaccessoncrossreferenceentit.html

0

I had this error, and finally figured out that it wasn't a security issue, but bad data in the system - the ID that was causing the error was from a different org, and wasn't valid in the current org. Ehh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .