function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kathyanikathyani 

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id

Hi,

I never had problems running my test method on my developer's edition before.

But now I created a new salesforce account and have all my triggers here. I am getting an error when I run my test method on this newly created instance.

Error:
DML Operation executed in 180 ms
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id


Do I need to set some rights/roles or privileges on this newly created account? Quick help would be appreciated.



Thanks,
Kathyani
Best Answer chosen by Admin (Salesforce Developers) 
mikefmikef
Please post the offending code block, my guess is you have hard coded an ID from test and are using it in your code.
Now that you are in production the server can't find the object you are looking for.

Or another reason this could happen is the user doing executing the code doesn't have rights to a record type you have in test.

As an admin in production do you get the same error?

All Answers

mikefmikef
Please post the offending code block, my guess is you have hard coded an ID from test and are using it in your code.
Now that you are in production the server can't find the object you are looking for.

Or another reason this could happen is the user doing executing the code doesn't have rights to a record type you have in test.

As an admin in production do you get the same error?
This was selected as the best answer
kathyanikathyani
I am a system admin on this. Below is the code. How do I change the rights of a record type in SF. I am trying to test the below code in apex test runner using testmethod.

static testMethod void testBillAfterTrigger() {
      
       // First Bill
        Bill__c bill1 = new Bill__c();
        bill1.ServiceNumber__c = '(111) 555-5555';
        bill1.ServiceName__c = 'at&t';
        bill1.RatePlanName__c = 'My New Test Plan';
        bill1.ATTDownloadDateString__c = '100107';
        bill1.TotalMinutesOfUse__c = 800.0;
        bill1.MonthlyAccessCharges__c = 100.0;
        bill1.TotalCurrentCharges__c = 355.0;
        bill1.FoundationAccountNumber__c = 'TESTFAN';
   
               
           
       // Second Bill
        Bill__c bill2 = new Bill__c();
        bill2.ServiceNumber__c = '(333) 555-5555';
        bill2.ServiceName__c = 'verizon';
        bill2.RatePlanName__c = 'My New Test Plan';
        bill2.ATTDownloadDateString__c = '120107';
        bill2.TotalMinutesOfUse__c = 800;
        bill2.MonthlyAccessCharges__c = 400.0;
        bill2.TotalCurrentCharges__c = 555.0;
        bill2.FoundationAccountNumber__c = 'TESTFAN';
    
        // Create a list of all the above bills
        List <Bill__c> bList = new List<Bill__c>();
        bList.add(bill1);
        bList.add(bill2);     
       
        System.debug('bList size' + bList.size());
        insert bList;
}
mikefmikef
what is the FoundationAccountNumber__c field?
is it a lookup to accounts?
kathyanikathyani
It is a custom field of type String.
mikefmikef
then you have to have a trigger on Bill__c that is causing this, because from what you posted you shouldn't get this error.

Please post the trigger or code on Bill__c, the apex error message should tell you what class or trigger and the line of the offending code.
kathyanikathyani
Yes you are correct. There was an SOQL which was returning zero rows. Once I fixed the data in that table so that the query returned non zero rows , it did not display that error.

Thanks for your help.