Why am i getting INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY error on code that worked before summer 13 update?

  • 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?

    What's the hardcoded ID that you're using? You should never use hardcoded IDs in code or tests!

    @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

    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: http://www.laceysnr.com/2013/06/smartfactory-easier-salesforce-test.html I can't say why something has changed but I suspect that is it.

    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?

  • Ben

    Ben Correct answer

    8 years ago

    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.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used