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
PallavPallav 

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY.. Need help !!

Hi All,

I am writting a unit testing method for my apex trigger and when running the following piece of code in the apex class I get the error message INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY while creating the "OpportunityLineItemSchedule". I have tried putting the "OpportunityLineItemId" hard coded then also it is showing the same error message. I cannot re move this as this is a required field.

public class testCodeCoverage
{
    static testMethod void myTest()
    {
        OpportunityLineItem acccobj = new OpportunityLineItem(OpportunityId = 'AAAAAAAAAA', Description='This is a test descriptiion',Quantity=3,UnitPrice=5000,PricebookEntryId='11111');
        insert acccobj;
        OpportunityLineItemSchedule acccobj1 = new OpportunityLineItemSchedule(OpportunityLineItemId=acccobj.Id,Description='This is a test description',Revenue=10000,ScheduleDate=Date.newInstance(2008,02,02),Quantity=2,Type='both');
        insert acccobj1;
    }
}

Thanks in anticipation of your kind and helpful response.

thanks and regards
pallav
Best Answer chosen by Admin (Salesforce Developers) 
mikefmikef
Pallav:

I think the issues are; you are trying to update an SObject but calling insert, and you only need to use Id not OpportunityLineItemId=...

Your code:
Code:
OpportunityLineItemSchedule acccobj1 = new OpportunityLineItemSchedule(OpportunityLineItemId=acccobj.Id,Description='This is a test description',Revenue=10000,ScheduleDate=Date.newInstance(2008,02,02),Quantity=2,Type='both');
insert acccobj1;

 I am not sure becuase the error really doesn't tell you much, but what you are doing might cause this error.

There is nothing "wrong" with your code other then those two things.

Change your code to this:

Code:
OpportunityLineItemSchedule acccobj1 = new OpportunityLineItemSchedule(Id=acccobj.Id,Description='This is a test description',Revenue=10000,ScheduleDate=Date.newInstance(2008,02,02),Quantity=2,Type='both');
update acccobj1;

 







Message Edited by mikef on 02-08-2008 02:55 PM

All Answers

mikefmikef
Pallav:

I think the issues are; you are trying to update an SObject but calling insert, and you only need to use Id not OpportunityLineItemId=...

Your code:
Code:
OpportunityLineItemSchedule acccobj1 = new OpportunityLineItemSchedule(OpportunityLineItemId=acccobj.Id,Description='This is a test description',Revenue=10000,ScheduleDate=Date.newInstance(2008,02,02),Quantity=2,Type='both');
insert acccobj1;

 I am not sure becuase the error really doesn't tell you much, but what you are doing might cause this error.

There is nothing "wrong" with your code other then those two things.

Change your code to this:

Code:
OpportunityLineItemSchedule acccobj1 = new OpportunityLineItemSchedule(Id=acccobj.Id,Description='This is a test description',Revenue=10000,ScheduleDate=Date.newInstance(2008,02,02),Quantity=2,Type='both');
update acccobj1;

 







Message Edited by mikef on 02-08-2008 02:55 PM
This was selected as the best answer
PallavPallav
Hi,

Thanks a lot for replying... your advice really remoevd the error message that was comming... I really appriciate your help.

regards
pallav
Alexander_EAlexander_E

Hi mikef,

 

I have coded my Testclass, as you mentioned here in the blog, but I really don't understand, why I should use "update" instead of insert for the opportuntiylineitemschedule. 

 

updating theSchedule, that is not inserted before, cause a DmlException.

 

inserting theSchedule, cause a DmlException as mentioned in the subject line "INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY"

 

		// oli = OpportunityLineItem
		OpportunityLineItem oli = new OpportunityLineItem();
		oli.OpportunityId = opp.Id;
		oli.PricebookEntryId = pbe.Id;
		oli.ServiceDate = onedate;
		oli.Quantity = 2.0;
		oli.TotalPrice = oli.Quantity * sumTotalPrice;
		insert oli;
		oli = [SELECT Id, HasSchedule, HasRevenueSchedule, HasQuantitySchedule, OpportunityId, PricebookEntryId, ServiceDate, Quantity, TotalPrice FROM OpportunityLineItem WHERE OpportunityId =: opp.Id LIMIT 1];
		
		// olis = OpportunityLineItemSchedule
		OpportunityLineItemSchedule olis = new OpportunityLineItemSchedule(
		Type='both', 
		Revenue = 2, 
		Quantity = 1,
		OpportunityLineItemId = oli.Id,
		ScheduleDate=onedate
		);
		insert olis;

 

any hints would be wonderful