+ Start a Discussion
Markey1Markey1 

Apex Coverage Error - Isufficient_Access_On_Cross_Reference_Entity

This code was created by another developer and I need to achieve higher coverage to deploy an unrelated project. My test class (psuControllerTest) is receiving a test failure. It looks like it does not like the last part of the code where the "Status" is set. Any help with correcting the test code is much appreciated.

 

Method Name:

psuControllerTest.testPsuIdRequest

 

Message:

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

 

Stack Trace:

Class.psuIdRequestController.setStatus: line 88, column 13 Class.psuIdRequestController.Approve: line 45, column 9 Class.psuControllerTest.testPsuIdRequest: line 176, column 9 External entry point

 

 

Test class snippet:

     static testMethod void hierarchyControllerTest() {
        Id profileid = [Select id from Profile where name = 'Customer Portal Manager Custom'].id;
        Account account = new Account(Name = 'Test Account'); 
        
        insert account; 
        Contact businessContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'BusinessUser', email = 'bustest@test.com' ); 
        Contact technicalContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'TechnicalUser', email = 'tectest@test.com' ); 
        Contact financeContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'FinanceUser', email = 'fintest@test.com' );
        Contact treasuryContact = new Contact(AccountID = account.id, FirstName = 'Test', LastName = 'TreasuryUser', email = 'tretest@test.com' ); 
        Contact[] contacts = new Contact[]{businessContact,technicalContact,financeContact,treasuryContact};
        insert contacts;

        User BusinessUser = new User(email='business@test.com', 
                                     contactid = businessContact.id, 
                                     profileid = profileid, 
                                     UserName='business@test.com', 
                                     alias='bususer', CommunityNickName='bususer',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'BusinessUser');
        User TechnicalUser = new User(email='technical@test.com', 
                                     contactid = technicalContact.id, 
                                     profileid = profileid, 
                                     UserName='technical@test.com', 
                                     alias='tecuser', CommunityNickName='tecuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'TechnicalUser');
        User FinanceUser = new User(email='finance@test.com', 
                                     contactid = financeContact.id, 
                                     profileid = profileid, 
                                     UserName='finance@test.com', 
                                     alias='finuser', CommunityNickName='finuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'FinanceUser');
        User InvalidUser = new User(email='treasury@test.com', 
                                     contactid = treasuryContact.id, 
                                     profileid = profileid, 
                                     UserName='treasury@test.com', 
                                     alias='treuser', CommunityNickName='treuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test', 
                                     LastName = 'TreasuryUser');
        User[] users = new User[]{businessUser,technicalUser,financeUser,InvalidUser};
        insert users;    
        //Create a Request
        Participant_ID_Request__c request = new Participant_ID_Request__c(
        Name='New Hierarchy Test',
        Business_Approver__c = BusinessUser.ContactId, 
        Techincal_Approver__c  = TechnicalUser.ContactId, 
        Finance_Approver__c = FinanceUser.ContactId,  
        Treasury_Hierarchy_Approver__c = InvalidUser.ContactId
        );
        insert request;
        
        //Create a Hierarchy
        Participant_Hierarchy__c hierarchy = new Participant_Hierarchy__c(
        Name='Hierarchy Test',
        Business_Approver__c = BusinessUser.ContactId, 
        Technical_Approver__c  = TechnicalUser.ContactId,  
        Finance_Approver__c = FinanceUser.ContactId,
        Treasury_Hierarchy_Approver__c = InvalidUser.ContactId,
        Business_Approval__c = 'Pending', 
        Technical_Approval__c = 'Pending', 
        Finance_Approval__c = 'Pending',
        Treasury_Approval__c = 'Pending',
        Treasury_Comments__c = 'Test',
        Business_Comments__c = 'Test', 
        Technical_Comments__c= 'Test', 
        Finance_Comments__c= 'Test',
        New_Participant__c = request.Id
        );
        insert hierarchy;
    
                
        // Test class Complete_Requirements_Status methods 
        ApexPages.standardController hierarchyCntl = new ApexPages.standardController(hierarchy);
        Test.setCurrentPageReference(new PageReference('Page.hierarchyreview')); 
        System.currentPageReference().getParameters().put('requestid', request.Id);
        psuHierarchyController reviewController = new psuHierarchyController(hierarchyCntl);
        Participant_Hierarchy__c objHierarchy = reviewController.gethierarchy();
            
         //Test as Portal User
        String strStatus; 
        
        System.RunAs(BusinessUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs

        System.RunAs(TechnicalUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs
        System.RunAs(FinanceUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs
        System.RunAs(InvalidUser)
        {
            String strApprover = reviewController.getApprover();
            String strComment = reviewController.getComment();
            reviewController.setComment(strComment);
            strStatus = reviewController.getStatus();
        } //end RunAs

        reviewController.approve();
            
        reviewController.reject();

        reviewController.setStatus(strStatus);
        
        String hn = reviewController.getHierarchyName();
        String approver = reviewController.getApprover();
        Attachment attachment = reviewController.attachment;
        Attachment[] attachments = reviewController.attachments;
        
    }

 

Markey1Markey1

Thanks for the link kritin. From the info provided, I'm not sure if it applies... looks like you can make updates on setup Objects for the User etc. I've been trying to wrap my brain around a fix... any suggestions on changes to the code?

 

This is expected behavior, and it is due to the fact that Apex language does not allow updates on setup Objects from Apex requests, with the exception of User, Group, Group Member, and Queue objects.