You need to sign in to do that
Don't have an account?

first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
here is my controller class
public without sharing class UpdateList {
list<order> selectorder;
String quoteId {set; get;}
String selectedOrderId {set; get;}
public List<Order> selectedOrders {set; get;}
public Boolean orderUpdated {set; get;}
public UpdateList(){
quoteId = ApexPages.currentPage().getParameters().get('quoteID');
orderUpdated = false;
}
public PageReference selectOrder(){
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
return null;
}
public list<Order> getorderslist()
{
List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
return allords;
}
//call this method to update order, and copy all quote line items from quote
public PageReference updateOrder(){
//get selected orderId from the list
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
//get quote line items using the quoteId
List<OrderItem> orderLines = new List<OrderItem>();
for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate,
Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
OrderItem oLine = new OrderItem();
oLine.OrderId = selectedOrderId;
oLine.PricebookEntryId = qLine.PricebookEntryId;
oLine.Quantity = qLine.Quantity;
oLine.UnitPrice = qLine.UnitPrice;
oLine.Description = qLine.Description;
oLine.ServiceDate = qLine.ServiceDate;
orderLines.add(oLine);
}
insert orderLines;
orderUpdated = true;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
return null;
}
}
here my test class
@istest (seeAllData=true)
private without sharing class TestUpdateList{
Private static Account a;
Private static Contact c;
Private static Opportunity opp;
Private static Quote q;
Private static QuoteLineItem Qli;
private static Order o;
Static {
// Creating the data for Account,Contact,Opportunity,Quote and Order.
a=new Account(Name='test1',Phone='9458383336'); // creating account with only mandatory Fields
insert a;
c = new Contact(LastName='Test',AccountId=a.Id); // creating contact with only mandatory Fields
insert c;
// creating opportunity with only mandatory Fields
opp = new Opportunity(Name='Test Opp',AccountId=a.Id,StageName='closedwon',CloseDate=Date.Today());
insert opp;
Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
Product2 p = new product2(name='test',family='test',productcode='12345');
insert p;
System.debug('### p:'+p);
PricebookEntry pbe = new PricebookEntry(pricebook2id=stdPb.id, product2id=p.id,
unitprice=1.0, isActive=true,UseStandardPrice=false);
insert pbe;
// Creating Quote with only mandatory Fields
q=new Quote(Name='testquote',opportunityId=opp.Id, pricebook2id=stdPb.id);
insert q;
// Creating Quote Line Items PricebookEntryId, Product2Id
qli=new QuoteLineItem(QuoteId=q.Id,pricebookentryid=pbe.id, Quantity=12,UnitPrice=1500,Discount=0,Description='nothing',ServiceDate=system.today());
insert qli;
// Creating Order with mandatory Fields
o=new Order(AccountId=a.Id,Name='test',status='draft',EffectiveDate=system.today());
insert o;
}
// retreiving the order record and working fine 25% code coverage with this method.
Static TestMethod void Testgetorderslist(){
Test.StartTest();
PageReference pageRef=page.PrevOrder;
pageRef.getParameters().put('quoteID',q.Id);
Test.SetCurrentPageReference(pageRef);
UpdateList ul=new UpdateList();
List<order> orderList = ul.getorderslist();
pageRef.getParameters().put('selectOrder',o.Id);
ul.SelectOrder();
ul.updateOrder();
system.debug('test result ='+ orderList);
system.assertEquals(orderList.size(),1);
Test.StopTest();
}
Static TestMethod void TestselectOrder(){
Test.StartTest();
PageReference pageRef=page.PrevOrder;
Test.SetCurrentPageReference(pageRef);
ApexPages.currentPage().getParameters().put('ordersRadio',o.Id);
ApexPages.StandardController sc = new ApexPages.standardController(o);
UpdateList controller=new UpdateList();
controller.SelectOrder();
controller.UpdateOrder();
Test.StopTest();
}
}
i am getting the above error when i run my test class.
how to solve this?
public without sharing class UpdateList {
list<order> selectorder;
String quoteId {set; get;}
String selectedOrderId {set; get;}
public List<Order> selectedOrders {set; get;}
public Boolean orderUpdated {set; get;}
public UpdateList(){
quoteId = ApexPages.currentPage().getParameters().get('quoteID');
orderUpdated = false;
}
public PageReference selectOrder(){
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
return null;
}
public list<Order> getorderslist()
{
List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
return allords;
}
//call this method to update order, and copy all quote line items from quote
public PageReference updateOrder(){
//get selected orderId from the list
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
//get quote line items using the quoteId
List<OrderItem> orderLines = new List<OrderItem>();
for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate,
Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
OrderItem oLine = new OrderItem();
oLine.OrderId = selectedOrderId;
oLine.PricebookEntryId = qLine.PricebookEntryId;
oLine.Quantity = qLine.Quantity;
oLine.UnitPrice = qLine.UnitPrice;
oLine.Description = qLine.Description;
oLine.ServiceDate = qLine.ServiceDate;
orderLines.add(oLine);
}
insert orderLines;
orderUpdated = true;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
return null;
}
}
here my test class
@istest (seeAllData=true)
private without sharing class TestUpdateList{
Private static Account a;
Private static Contact c;
Private static Opportunity opp;
Private static Quote q;
Private static QuoteLineItem Qli;
private static Order o;
Static {
// Creating the data for Account,Contact,Opportunity,Quote and Order.
a=new Account(Name='test1',Phone='9458383336'); // creating account with only mandatory Fields
insert a;
c = new Contact(LastName='Test',AccountId=a.Id); // creating contact with only mandatory Fields
insert c;
// creating opportunity with only mandatory Fields
opp = new Opportunity(Name='Test Opp',AccountId=a.Id,StageName='closedwon',CloseDate=Date.Today());
insert opp;
Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
Product2 p = new product2(name='test',family='test',productcode='12345');
insert p;
System.debug('### p:'+p);
PricebookEntry pbe = new PricebookEntry(pricebook2id=stdPb.id, product2id=p.id,
unitprice=1.0, isActive=true,UseStandardPrice=false);
insert pbe;
// Creating Quote with only mandatory Fields
q=new Quote(Name='testquote',opportunityId=opp.Id, pricebook2id=stdPb.id);
insert q;
// Creating Quote Line Items PricebookEntryId, Product2Id
qli=new QuoteLineItem(QuoteId=q.Id,pricebookentryid=pbe.id, Quantity=12,UnitPrice=1500,Discount=0,Description='nothing',ServiceDate=system.today());
insert qli;
// Creating Order with mandatory Fields
o=new Order(AccountId=a.Id,Name='test',status='draft',EffectiveDate=system.today());
insert o;
}
// retreiving the order record and working fine 25% code coverage with this method.
Static TestMethod void Testgetorderslist(){
Test.StartTest();
PageReference pageRef=page.PrevOrder;
pageRef.getParameters().put('quoteID',q.Id);
Test.SetCurrentPageReference(pageRef);
UpdateList ul=new UpdateList();
List<order> orderList = ul.getorderslist();
pageRef.getParameters().put('selectOrder',o.Id);
ul.SelectOrder();
ul.updateOrder();
system.debug('test result ='+ orderList);
system.assertEquals(orderList.size(),1);
Test.StopTest();
}
Static TestMethod void TestselectOrder(){
Test.StartTest();
PageReference pageRef=page.PrevOrder;
Test.SetCurrentPageReference(pageRef);
ApexPages.currentPage().getParameters().put('ordersRadio',o.Id);
ApexPages.StandardController sc = new ApexPages.standardController(o);
UpdateList controller=new UpdateList();
controller.SelectOrder();
controller.UpdateOrder();
Test.StopTest();
}
}
i am getting the above error when i run my test class.
how to solve this?
Try using System.runAs(System Administor) as Sys admin has all rights.